Nginx 404 troubleshooting process

Suddenly I visited my test domain name one day, and got a 404. Then, like a headless fly, I tried everywhere and looked at the configuration of nginx. I tried to find it to no avail. Finally, with the help of colleagues, I found some clues. Although these steps are very simple, they are the whole idea of ​​solving the problem.

1. Look at the access.log requested by nginx

Check the log of nginx configuration to confirm that the request has reached nginx.
Nginx log configuration instructions:

access_log /data/logs/nginx/api.access.log;
error_log  /data/logs/nginx/api.error.log;

2. Check whether the upstream access server port number specified by the domain name is correct

upstream my_service {
    
    
    # 192.168.1.10 Nginx 服务器,8899 是 Nginx 监听的端口号
    server 192.168.1.10:8899 weight=1;
}

The upstream configuration of my domain name is an Nginx server , and all requests are sent to that Nginx server and then forwarded to the back-end server. One day when I visited, a 404 suddenly appeared. I saw that the Nginx server was also started well, and the back-end service was also started normally.
Then I checked the port number it listened on on the Nginx server : netstat -anp | grep nginx
Insert picture description here
I found that the upstream server port number "8899" configured by my domain name is not in the above picture. It is possible that someone moved my configuration file and finally changed the domain name pointed to The upstream server port number, then 404 disappeared.

3. Check whether the back-end service is reachable

If you have requested to nginx, then look at whether the request to the back-end services,
make sure the back-end service is started up, this look at the rear end of the log should be able to find something, and through curl 127.0.0.1:8080that to see if you can access your service.

The cause of this problem may not be the same for everyone, but as long as there is a general direction for solving the problem in mind, you will not get stuck in it and fail to see the essence of the problem.

Guess you like

Origin blog.csdn.net/jiaobuchong/article/details/104847020