Home  >  Article  >  Operation and Maintenance  >  How to configure nginx 404 page

How to configure nginx 404 page

步履不停
步履不停Original
2019-06-21 11:58:384229browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn