nginx如何在使用proxy_pass以后依然能使用error_page?
时间:2016-05-23 23:03 来源:linux.it.net.cn 作者:IT
server {
listen 80;
server_name cz.test.com;
access_log /var/log/nginx/cz.test.com.access.log;
root /tmp/cz;
location / {
include /etc/nginx/proxy.conf;
error_page 404 = /about.html;
recursive_error_pages on;
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (-f $request_filename.html) {
rewrite (.*) $1.html break;
}
if (!-f $request_filename) {
proxy_pass http://172.20.2.160;
break;
}
}
}
如果没有proxy_pass肯定是没有问题的。怎么才能在使用proxy_pass之后error_page也管用呢,有没有大侠有过这个经验。
我主要想转一下维护页面,先拿404页面测试一下。
今天测试了一下午,找到你这个问题的答案了。
proxy_intercept_errors on;
比如:
server {
......
error_page 404 = /404.php;
location ^~ /car/ {
proxy_pass http://xxxxxx/car/;
proxy_intercept_errors on;
proxy_redirect default;
}
这样,当proxy_pass 出现的404,也会走/404.php
(责任编辑:IT)
server { listen 80; server_name cz.test.com; access_log /var/log/nginx/cz.test.com.access.log; root /tmp/cz; location / { include /etc/nginx/proxy.conf; error_page 404 = /about.html; recursive_error_pages on; if (-f $request_filename/index.html) { rewrite (.*) $1/index.html break; } if (-f $request_filename.html) { rewrite (.*) $1.html break; } if (!-f $request_filename) { proxy_pass http://172.20.2.160; break; } } } 如果没有proxy_pass肯定是没有问题的。怎么才能在使用proxy_pass之后error_page也管用呢,有没有大侠有过这个经验。 我主要想转一下维护页面,先拿404页面测试一下。 今天测试了一下午,找到你这个问题的答案了。 proxy_intercept_errors on; 比如: server { ...... error_page 404 = /404.php; location ^~ /car/ { proxy_pass http://xxxxxx/car/; proxy_intercept_errors on; proxy_redirect default; } 这样,当proxy_pass 出现的404,也会走/404.php (责任编辑:IT) |