无法通过 http 访问 nginx CentOS 7

标签 nginx centos

在vps上配置了nginx,但是通过http访问公网ip或者域名默认的index.html是访问不到的

nginx 配置

server {
    listen       80 default_server;
    server_name  domainname.com;
    root   /usr/share/nginx/html;
    index  index.html;

    location / {
    }
}

最佳答案

默认情况下centos 7防火墙是屏蔽端口80

需要编辑下一个文件

/etc/firewalld/zones/public.xml

添加80端口

<?xml version="1.0" encoding="utf-8"?>
<zone>
  <short>Public</short>
  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
  <service name="ssh"/>
  <service name="dhcpv6-client"/>
  <port protocol="tcp" port="80"/>
</zone>

重新加载防火墙

firewall-cmd --reload

关于无法通过 http 访问 nginx CentOS 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50898751/

相关文章:

python-2.7 - 当我关闭 bash 终端时,gunicorn 和 python 不工作

ubuntu - curl 错误无法解决我的主机问题,但可以通过 google 解决

linux - 使用 `ps -T -p [pid]` 时如何获取整个线程名称

linux - 似乎无法在 linux 上安装 id3v2,似乎没有任何错误

Nginx 如何在不修改 nginx.conf 的情况下添加额外的服务器配置

NGINX + uWSGI 连接被对等方重置

nginx - 如何查看 nginx 尝试访问文件的实际文件路径?

JAVA TLS 1.2 降级到 TLS 1.0 有时会报错

nginx - ERR_SPDY_PROTOCOL_ERROR在nginx中意味着什么?

linux - 如何为 su 或 sudo 设置 LD_PRELOAD?