Nginx error_page 自定义错误页面设置代码教程,nginxerror_page


Nginx error_page 自定义错误页面设置代码教程

#fastcgi_intercept_errors on;
    #语法:fastcgi_intercept_errors on|off 
    #默认值:fastcgi_intercept_errors off 
    #使用字段:http, server, location 
    #这个指令指定是否传递4xx和5xx错误信息到客户端,或者允许nginx使用error_page处理错误信息。
    #你必须明确的在error_page中指定处理方法使这个参数有效,正如Igor所说“如果没有适当的处理方法,
    #nginx不会拦截一个错误,这个错误不会显示自己的默认页面,这里允许通过某些方法拦截错误。


    #proxy_intercept_errors 为on 表示 nginx按照原response
    #proxy_intercept_errors on|off 
    #proxy_intercept_errors off 
    #使用字段:http, server, location    #code输出,后端是404,就是404.这个变量开启后,我们才能自定义错误页面。


    proxy_intercept_errors on;

    upstream dev1 {

        server 127.0.0.1:8080;          #HessianTest3

    }

    server {
        listen       80;
        server_name  kevin.com;



        location / {
            proxy_pass https://dev1;     #HessianTest3
        }

        #参考书本第40页
        #error_page 404 =200 /404.html;
        #error_page 500 502 503 504  =200 /50x.html;

        #location = /404.html {
        #   root html;
        #   
        #}

        #location = /50x.html {
        #    root   html;
        #}

        #当页面发生异常的时候可以指定跳转到location中,也可以指定跳转到指定的URL地址上面
        error_page 404 https://www.baidu.com/;
    }

相关内容