Fedora本地Web服务器正常,SSH客户端访问返回Nginx 404问题
问题:Fedora上Web服务器本地可访问,SSH远程访问返回Nginx 404错误
我在Fedora(6.13.9-200.fc41.x86_64)上搭建的Web服务器,在localhost:80能正常运行,但通过另一台SSH连接的机器访问时,返回Nginx 404 Not Found页面,页面内容如下:
404 Not Found 404 Not Foundnginx
我参考了Ubuntu的视频教程,但Ubuntu和RHEL系发行版配置差异大,过程中踩了不少坑,虽然完成配置还是出现这个错误。我的Apache配置文件/etc/httpd/conf.d/nc.marcosg.com.conf内容如下:
<VirtualHost *:80> DocumentRoot "/var/www/nc.marcosg.com" ServerName nc.marcosg.com <Directory "/var/www/nc.marcosg.com/"> Options MultiViews FollowSymLinks AllowOverride All Require all granted </Directory> TransferLog /var/log/httpd/nc.marcosg.com_access.log ErrorLog /var/log/httpd/nc.marcosg.com_error.log </VirtualHost>
/etc/hosts已配置自定义域名:
3 │ 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 4 │ 127.0.1.1 nc.marcosg.com nc 5 │ ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
我对Ubuntu转RHEL系的Web服务器配置不熟悉,推测问题可能出在nginx、httpd/apache、SELinux或隧道配置上。
排查与解决步骤
1. 解决端口冲突(核心排查点)
返回的是Nginx的404页面,说明当前是Nginx在监听80端口,而非你配置的Apache:
- 检查服务状态:
systemctl status nginx systemctl status httpd - 停止并禁用Nginx,避免自动启动:
systemctl stop nginx && systemctl disable nginx - 重启Apache加载配置:
systemctl restart httpd - 验证端口监听进程:
确保输出中显示的是ss -tulpn | grep :80httpd进程,而非nginx。
2. 验证远程机器的域名解析
远程机器无法直接使用Fedora本地的/etc/hosts配置,需确保它能将nc.marcosg.com解析到Fedora服务器的真实IP:
- 在远程机器执行:
若返回的是127.0.0.1,需在远程机器的ping nc.marcosg.com/etc/hosts中添加映射:# 替换为你的Fedora服务器局域网/公网IP xxx.xxx.xxx.xxx nc.marcosg.com nc
3. 修复SELinux权限限制
RHEL系默认开启SELinux,可能阻止Apache访问网站目录:
- 给网站目录添加正确的SELinux上下文:
chcon -R -t httpd_sys_content_t /var/www/nc.marcosg.com/ - 若网站需要写入权限(比如上传功能),额外执行:
chcon -R -t httpd_sys_rw_content_t /var/www/nc.marcosg.com/ - 可临时关闭SELinux测试(不推荐长期关闭):
测试正常后务必恢复SELinux并配置上下文,不要永久关闭。setenforce 0
4. 开放防火墙端口
Fedora默认使用firewalld,需允许外部访问80端口:
- 添加HTTP服务规则并重载:
firewall-cmd --add-service=http --permanent firewall-cmd --reload
5. 验证Apache配置与站点内容
- 检查Apache配置语法是否正确:
若有错误,根据提示修复配置文件后重启Apache。httpd -t - 查看Apache错误日志排查细节:
tail -f /var/log/httpd/nc.marcosg.com_error.log - 确认网站根目录存在且有默认页面:
确保目录下存在ls -la /var/www/nc.marcosg.com/index.html、index.php等Apache默认识别的索引文件。
内容的提问来源于stack exchange,提问作者YanMax
相关产品推荐
相关产品推荐

