I'm using Nginx as a load balancer with app servers behind it. If the app servers return a response of 404 not found, I would like nginx
to then server out a 404 page that is local on that server. I would like to do this so my app servers don't get tied up serving a static HTML file and can instead just quickly return a response and let nginx
handle serving the static stuff. Does anyone know how I can accomplish this? Basically I need some kind of conditional check based on the HTTP response. Is this possible? Thanks!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Simply set the proxy_intercept_errors
option to on and create an nginx error page for it.
error_page 404 /404.html;
proxy_intercept_errors on;
To ensure that nginx will serve the static file from it’s document root you also have to specify the following:
location /404.html {
internal;
}
I'm assuming here that nginx is configured to talk with your app servers as proxy, because that is the usual way and your question does not mention any of this.