Nginx页面不能访问排查思路

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 {
         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 {
         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

image.png-82.5kB

注意清理一下缓存呦~~

本篇文章摘选自:https://www.cnblogs.com/achengmu/p/9093981.html

原文地址:https://www.cnblogs.com/ywb123/p/13044089.html