Home >Operation and Maintenance >Nginx >How to configure nginx 404 page
Recently I set up a jump to the 404 page on the site. Because I am not very familiar with Nginx, I took a lot of detours. I will record it here and hope it can help everyone solve the problem. .
1. 404 page
First we need a 404 page. For this page, I put all the css, js and html in one page. It exists The location can be set by you. The location where I store it is in the nginx directory of the server. The name is 404.html
/etc/nginx/error/404.html
2. nginx configuration file
We need to Configure the jump to the 404 error page in the nginx.conf file
http { ... ... ... server { ... ... ... error_page 404 /404.html; location = /404.html { root /etc/nginx/error; } } }
Most of the ones you can find on the Internet are like this, and then I tried it many times but nothing worked. Finally, I found an article about I tried the attribute of proxy_intercept_errors and configured it as follows.
http { ... ... ... proxy_intercept_errors: on; ... ... ... server { ... ... ... error_page 404 /404.html; location = /404.html { root /etc/nginx/error; } } }
Then it’s OK. During the configuration process, I forgot to add a semicolon, which caused the page to display abnormally. You also need to pay attention here.
For more Nginx related technical articles, please visit the Nginx Tutorial column to learn!
The above is the detailed content of How to configure nginx 404 page. For more information, please follow other related articles on the PHP Chinese website!