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.

            http://192.168.1.202/

    ![nginx已經能夠成功訪問](https://img-blog.csdn.net/20171120104737429?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMjk3NjczMTc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
    這裏有一個小小的坑,希望大家注意一下,使用瀏覽器輸入ip訪問的時候,注意清空一下緩存,或者重新打開一下瀏覽器,有可能讓你一直刷新不出頁面。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章