Nginx configuration 404 custom page

Time:2021-11-28

1. Modify nginx.conf http

Nginx.conf file HTTP area addfastcgi_intercept_errors on;

http {
    .......
    fastcgi_intercept_errors on;

2. Configure conf server

to configureerror_page 404

server {
    listen 80;
    server_name www.zhangguoye.com;
    index index.html index.htm;
    root /home/wwwroot;
 
    error_page 404 /404.html;
    location = /404.html {
                root   /home/wwwroot/;  #  Add custom 404.html in this directory
    }

3. Restart nginx

userestartperhapsreloadRestart nginx to make the configuration effective.