lafang2009 发表于 2011-01-24 11:54

nginx如何在使用proxy_pass以后依然能使用error_page?

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页面测试一下。

maochanglu 发表于 2011-01-25 15:32

是不是因为设置了:recursive_error_pages on;

sss0213 发表于 2011-01-28 15:55

你的问题解决了吗?解决的话,写下解决方法吧?遇到同样的问题 :D

tjpm 发表于 2012-04-28 18:28

LZ可以试试设置一下 proxy_intercept_errors on;
这个要在1.1.x以上版本可以使用。


lafang2009 发表于 2011-01-24 11:54 static/image/common/back.gif
server {
        listen 80;
        server_name cz.test.com;

hjk857 发表于 2012-09-17 10:32

tjpm 发表于 2012-04-28 18:28 static/image/common/back.gif
LZ可以试试设置一下 proxy_intercept_errors on;
这个要在1.1.x以上版本可以使用。


有尝试了,没用。测试的版本是nginx-1.2.0

jorygong 发表于 2014-06-30 18:58

今天测试了一下午,找到你这个问题的答案了。
proxy_intercept_errors on;
比如:
server {
      ......
      error_page 404 = /404.php;
      location ^~ /car/ {
    proxy_passhttp://xxxxxx/car/;
    proxy_intercept_errors on;
    proxy_redirect default;
   }

这样,当proxy_pass 出现的404,也会走/404.php

你试试。


}
页: [1]
查看完整版本: nginx如何在使用proxy_pass以后依然能使用error_page?