linux nginx本机可以访问html,远程无法访问的解决办法

来源:互联网 发布:电脑人工智能软件 编辑:程序博客网 时间:2024/04/30 07:04


注意有三个问题需要解决:

1. centos7采用的是service firewalld而不是iptables作为防火墙  。 firewalld会阻止远程对linux的80端口的访问


2. 即使安装了iptables也需要开放80端口。

----如下去装iptables-servie

yum install iptables-services 

vi /etc/sysconfig/iptables 

添加如下一行

-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT


结果如下

# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
#Enable out access 80 port for Nginx.
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
COMMIT


-----

实际上是参考了-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT 这一行,改成80即可。



3. selinux 阻止了html文件下几个html文件的远程被访问。

参加我的博客“Nginx因Selinux服务导致无法远程访问



----

综上:

1.#systemctl stop firewalld

2.#systemctl stop iptalbes (如何装了iptables-service的话)

3.#vim /etc/selinux/config

改成SELINUX=disabled

4.#reboot

重启后。

$ getenforce
Disabled
并且执行上方的第1,2步骤, 再启动nginx, 就能远程访问nginx网站了。



0 0
原创粉丝点击