nginx 404 跳转到自定义的页面

时间:2022-11-07 22:51:11

1. 自己写了一个error.html页面


2. 更改nginx.conf在http定义区域加入: fastcgi_intercept_errors on;


3. 更改nginx.conf中在server 区域加入: error_page 404  /404.html 


4. 重启ngnix


另外,有一个8000端口的错误页面也要跳转到80的error页面,

在server 8000下添加 error_page 404 error, 另外 include error.conf


# the difference when adding URI to proxy_pass directive:
# http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

# why I use variable but not staticlly config the url:
# http://forum.nginx.org/read.php?2,215830,215832#msg-215832
#
# and resolver is needed, or will get 502, ref:
# https://*.com/questions/5743609/
#
# why use rewrite: http://wiki.nginx.org/HttpProxyModule#proxy_pass

resolver 127.0.0.1;

location /error {
    proxy_pass  http://127.0.0.1:80;
}

location /images {
    proxy_pass  http://127.0.0.1:80;
}

location /js {
    proxy_pass  http://127.0.0.1:80;
}

location /css {
    proxy_pass  http://127.0.0.1:80;
}