Nginx不能正常访问排除方法,nginx访问排除方法


Nginx页面不能访问

1. 检查服务端服务是否启动成功

[root@shizhan02 html]# ps -ef |grep nginx  #查看nginx服务是否启动
root       1609      1  0 16:46 ?        00:00:00 nginx: master process nginx
nginx      1610   1609  0 16:46 ?        00:00:00 nginx: worker process
root       1898   1593  0 18:09 pts/0    00:00:00 grep nginx
[root@shizhan02 html]# lsof -i :80  #检查80端口是否在监听状态
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   1609  root    6u  IPv4  11948      0t0  TCP *:http (LISTEN)
nginx   1610 nginx    6u  IPv4  11948      0t0  TCP *:http (LISTEN)
[root@shizhan02 html]# netstat -lnt |grep 80 
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN 

2.在服务端使用wget和curl测试下返回的是否正常

[root@shizhan02 html]# wget 127.0.0.1
--2017-11-20 18:16:58--  http://127.0.0.1/
Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response... 200 OK #返回值200表示链接正常
Length: 612 [text/html]
Saving to: “index.html.2”

100%[===============================================================>] 612         --.-K/s   in 0s      

2017-11-20 18:16:58 (279 MB/s) - “index.html.2” saved [612/612]

[root@shizhan02 html]# curl 127.0.0.1 #返回页面的值表示正常。
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

以上是检测Nginx在服务端安装及浏览是否正常。

3.浏览器,wget或者curl等软件访问不了Ngixn页面。

    1. 关闭SEliun
    ```
    [root@shizhan02 html]# getenforce #查看iptables状态,是否为关闭,以下为关闭状
    态,
    Disabled
    [root@shizhan02 html]# vim /etc/selinux/config #永久关闭iptalbes
    SELINUX=disabled #需要将此行更改为disabled
    SELINUXTYPE=targeted

    [root@shizhan02 html]# setenforce 0 #临时关闭iptables的方法,如果临时能够访问
    了,那么久使用下面的方法添加80端口在iptables的配置文件上
    setenforce: SELinux is disabled

    [root@shizhan02 html]# service iptables status   #检查iptables
    Table: filter
    Chain INPUT (policy ACCEPT)
    num  target     prot opt source               destination         

    Chain FORWARD (policy ACCEPT)
    num  target     prot opt source               destination         

    Chain OUTPUT (policy ACCEPT)
    num  target     prot opt source               destination  

    问题不是出在nginx上,而是出在iptable上,在iptable上添加80端口

    Linux代码  收藏代码
    #vi /etc/sysconfig/iptables  
    //在倒数第二行加入80端口  
    -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j
     ACCEPT  


    //重启iptables  
    #/etc/init.d/iptables restart  
     再通过ip访问  ok~  没问题了
    ```
2. 通过本地客服端测试
    第一步:在客服端ping服务端的ip,我这里的的服务端为192.168.1.202
    ```
    [root@shizhan02 html]# ping 192.168.1.202
    PING 192.168.1.202 (192.168.1.202) 56(84) bytes of data.
    64 bytes from 192.168.1.202: icmp_seq=1 ttl=64 time=0.014 ms
    64 bytes from 192.168.1.202: icmp_seq=2 ttl=64 time=0.024 ms
    ^C
    --- 192.168.1.202 ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 1814ms
    rtt min/avg/max/mdev = 0.014/0.019/0.024/0.005 ms
    #提示按ctrl+c结束
    ```
    第二步:在客户端上telnet服务端ip,端口
    ```
    [root@shizhan02 html]# telnet 192.168.1.202 #返回如下信息表示链接成功
    Trying 192.168.1.202...
    telnet: connect to address 192.168.1.202: Connection refused
    ```

        第三步:在客服端使用wget或者curl命令检测。
        ```
        [root@shizhan02 html]# curl -i 192.168.1.202
        HTTP/1.1 200 OK
        Server: nginx/1.13.6
        Date: Mon, 20 Nov 2017 10:42:31 GMT
        Content-Type: text/html
        Content-Length: 612
        Last-Modified: Mon, 20 Nov 2017 08:08:26 GMT
        Connection: keep-alive
        ETag: "5a128d7a-264"
        Accept-Ranges: bytes

        <!DOCTYPE html>
        <html>
        <head>
        <title>Welcome to nginx!</title>
        <style>
            body {
                width: 35em;
                margin: 0 auto;
                font-family: Tahoma, Verdana, Arial, sans-serif;
            }
        </style>
        </head>
        <body>
        <h1>Welcome to nginx!</h1>
        <p>If you see this page, the nginx web server is successfully
         installed and
        working. Further configuration is required.</p>

        <p>For online documentation and support please refer to
        <a href="http://nginx.org/">nginx.org</a>.<br/>
        Commercial support is available at
        <a href="http://nginx.com/">nginx.com</a>.</p>

        <p><em>Thank you for using nginx.</em></p>
        </body>
        </html>
        ```
        3. 在浏览器访问输入如下的内容,服务器ip.

接着检查了服务器端的80端口是否可以访问的到 ,如果访问不到,那么就是防火墙的问题。

   做如下处理:

[plain] view plain copy
  1. [root@localhost ]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT  
  2. [root@localhost ]# /etc/init.d/iptables save  
  3. [root@localhost ]# /etc/init.d/iptables restart  


   至此,OK了,主机已可访问虚拟机的nginx服务。

相关内容

    暂无相关文章