Nginx頁面不能訪問排查思路
nginx頁面不能訪問:
- 檢查服務端服務是否啟動成功
- 在服務端使用wget和curl測試下返回的是否正常
- 瀏覽器wget或者curl等軟件訪問不了Ngixn頁面
1. 檢查服務端服務是否啟動成功
#查看nginx服務是否啟動
[root@nginx ~]# ps -ef |grep nginx
root 1316 1 0 15:17 ? 00:00:00 nginx: master process nginx
nginx 1354 1316 0 15:25 ? 00:00:00 nginx: worker process
root 1369 1278 0 15:29 pts/1 00:00:00 grep --color=auto nginx
#檢查80端口是否在監聽狀態
[root@nginx ~]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 1316 root 6u IPv4 21465 0t0 TCP *:http (LISTEN)
nginx 1354 nginx 6u IPv4 21465 0t0 TCP *:http (LISTEN)
[root@nginx ~]# netstat -antup | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1316/nginx: master
2. 在服務端使用wget和curl測試下返回的是否正常
[root@nginx ~]# wget 127.0.0.1
--2020-06-04 15:32:21-- http://127.0.0.1/
正在連接 127.0.0.1:80... 已連接。
已發出 HTTP 請求,正在等待回應... 200 OK
長度:612 [text/html]
正在保存至: “index.html”
100%[====================================================================>] 612 --.-K/s 用時 0s
2020-06-04 15:32:21 (71.7 MB/s) - 已保存 “index.html” [612/612])
[root@nginx ~]# 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頁面。
3.1 檢查本地selinux和防火牆是否關閉
#檢查SEliunx
[root@nginx ~]# getenforce
Disabled
#(1)臨時關閉SEliunx
[root@nginx ~]# setenforce 0
#(2)永久關閉SEliunx
[root@nginx ~]# vim /etc/selinux/config
SELINUX=disabled #需要將此行更改為disabled
SELINUXTYPE=targeted
#檢查防火牆狀態
[root@nginx ~]# systemctl status firewalld.service
#關閉防火牆
[root@nginx ~]# systemctl stop firewalld.service
#永久關閉防火牆,禁止開機自啟動
[root@nginx ~]# systemctl disable firewalld.service
3.2 通過本地客服端測試
#第一步:在客服端ping服務端的ip,我這里的的服務端為192.168.200.30
[root@nginx-client ~]# ping 192.168.200.30 -c 5
PING 192.168.200.30 (192.168.200.30) 56(84) bytes of data.
64 bytes from 192.168.200.30: icmp_seq=1 ttl=64 time=0.436 ms
64 bytes from 192.168.200.30: icmp_seq=2 ttl=64 time=0.529 ms
64 bytes from 192.168.200.30: icmp_seq=3 ttl=64 time=0.359 ms
64 bytes from 192.168.200.30: icmp_seq=4 ttl=64 time=0.589 ms
64 bytes from 192.168.200.30: icmp_seq=5 ttl=64 time=0.279 ms
--- 192.168.200.30 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4009ms
rtt min/avg/max/mdev = 0.279/0.438/0.589/0.113 ms
#第二步:在客戶端上telnet服務端ip,端口
[root@nginx-client ~]# telnet 192.168.200.30 80
Trying 192.168.200.30...
Connected to 192.168.200.30.
Escape character is '^]'.
#第三步:在客服端使用wget或者curl命令檢測。
[root@nginx-client ~]# wget 192.168.200.30
--2020-06-04 15:55:32-- http://192.168.200.30/
正在連接 192.168.200.30:80... 已連接。
已發出 HTTP 請求,正在等待回應... 200 OK
長度:612 [text/html]
正在保存至: “index.html”
100%[====================================================================>] 612 --.-K/s 用時 0s
2020-06-04 15:55:32 (37.2 MB/s) - 已保存 “index.html” [612/612])
[root@nginx-client ~]# curl -i 192.168.200.30
HTTP/1.1 200 OK
Server: nginx/1.18.0
Date: Thu, 04 Jun 2020 07:54:41 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 21 Apr 2020 15:07:31 GMT
Connection: keep-alive
ETag: "5e9f0c33-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.3 在瀏覽器訪問服務器ip:http://192.168.200.30

注意清理一下緩存呦~~
