当 Fedora 28 服务器上的 Web 服务无法访问时,防火墙配置通常是主要原因之一。以下是详细的解决方案:
首先确认防火墙是否正在运行:
sudo systemctl status firewalld
如果防火墙未运行,可以启动它:
sudo systemctl start firewalld
sudo systemctl enable firewalld
查看当前防火墙配置:
sudo firewall-cmd --list-all
根据您的 Web 服务类型,添加相应规则:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --permanent --add-port=8080/tcp
应用更改:
sudo firewall-cmd --reload
再次检查防火墙规则:
sudo firewall-cmd --list-all
您应该能看到 http 和/或 https 服务在服务列表中。
# 允许 HTTP 服务
sudo setsebool -P httpd_can_network_connect on
# 如果您修改了默认端口,需要告诉 SELinux
sudo semanage port -a -t http_port_t -p tcp 8080
sudo netstat -tulnp | grep -E '80|443'
确保您的 Web 服务正在监听 0.0.0.0 (所有接口) 或特定的公共 IP 地址。
从另一台机器测试连接:
curl http://your-server-ip
或者使用浏览器访问服务器 IP。
确保所有更改在重启后仍然有效:
sudo firewall-cmd --runtime-to-permanent
端口被其他服务占用:
sudo ss -tulnp | grep :80
Web 服务未运行:
sudo systemctl status httpd # 对于 Apache
sudo systemctl status nginx # 对于 Nginx
网络连接问题:
ping your-server-ip
traceroute your-server-ip
通过以上步骤,您应该能够解决 Fedora 28 服务器因防火墙配置导致的 Web 访问问题。