4

#Nginx 重写反向代理proxy_pass的错误页

 2 years ago
source link: https://xmanyou.com/nginx-set-customer-error-page-for-proxy-server/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
15 September 2021 / Nginx

#Nginx 重写反向代理proxy_pass的错误页

Nginx经常用来做反向代理,直接将请求转发给目标服务器,然后把响应数据返回给客户端。

但是,有时候目标服务器返回的错误信息中包含了敏感信息,直接发给用户端,可能会暴露目标服务器。

这要怎么处理呢?

方法就是利用proxy_intercept_errors参数来捕获目标服务器返回的错误,返回自定义错误页给客户端。

1). 设置捕获错误

proxy_intercept_errors on;

proxy_intercept_errors设置为on以后,目标服务器返回的300以上的错误都会被捕获。

2). 设置错误页

        error_page 404 /404.html;
        location = /404.html {
                root /usr/share/nginx/html;
                internal;
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
                internal;
        }

阿斌

Read more posts by this author.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK