Nginx设置404错误页面跳转

3133

在http下配置 proxy_intercept_errors on;


http {
    include       mime.types;
    default_type  application/octet-stream;
    
      proxy_intercept_errors on;
      ... 以下省略

在server下配置 error_page


1.第一种配置情况(跳转网络地址)

server {
   listen 80;
   server_name www.xxxxxxx.com;
   error_page 404 http://www.baidu.com;
}


2.第二种配置情况(跳转本地地址)

server {
   listen 80;
   server_name www.xxxxxxx.com;
   error_page  404  /404.html;
   location = /404.html {
        #使用绝对地址, 跳转服务器/usr/local/nginx/html/404.html
        root   /usr/local/nginx/html;
    }
}


可以配置多种返回码的多个错误页面,也可以同时配置多个错误码跳转一个页面,可以同时存在 如下所示:

error_page 500 502 503 504 /50x.html;
location = /50x.html {
      #使用相对地址, 跳转nginx安装目录下的html/404.html
    root html;
}

error_page   500 502 503 504  /404.html;
error_page   404  /404.html;
location = /404.html {
   root   html;
}