我正在使用Nginx反向代理来访问在线drupal服务器上的内容。 事实是,如果Nginx失去他的互联网连接,当我试图通过反向代理调用服务器,我希望他给我回一个错误代码,说他没有设法连接远程服务器,超时,但是我唯一回来的是302代码,所以不能使用proxy_intercept_errors进行捕获。
我想要的是:如果Ngnix由于任何原因(404,50x,根本没有互联网)无法访问服务器,我希望他给我一个很好的,特定的错误页面(如果错误代码400或更高,但如果Nginx不能访问互联网)。
我使用的conf是:
# Reverse proxy for remote hosts # regex capture, $1 is hostname $2 is the rest of the URI location ~* /reverseproxy/([^/]*)(.*) { $$$RESOLVER_DNS_ADRESSES_TOKEN$$$ proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_redirect off; proxy_buffering off; proxy_set_header Host $1; proxy_cache_bypass 1; proxy_no_cache 1; proxy_intercept_errors on; # Tranform custom X-Cookie into regular Cookie header set $cookieValue ""; if ($http_x_cookie) { set $cookieValue $http_x_cookie; } proxy_set_header Cookie $cookieValue; # CORS headers proxy_hide_header Access-Control-Allow-Origin; proxy_hide_header Access-Control-Allow-Methods; proxy_hide_header Access-Control-Allow-Headers; proxy_hide_header Access-Control-Allow-Credentials; add_header Access-Control-Allow-Credentials true; add_header Access-Control-Allow-Origin http://localhost:8080; add_header Access-Control-Allow-Methods 'OPTIONS, GET, POST'; add_header Access-Control-Allow-Headers 'Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, Cookie'; send_timeout 10s; proxy_connect_timeout 5s; proxy_pass http://$1$2$is_args$query_string; }
互联网宕机时给出的答案的例子:
127.0.0.1 – – [01 / Feb / 2013:14:54:02 +0100]“GET /reverseproxy/xx.xxx.xx.xx/info.php> HTTP / 1.1”302 160“ – ”“Mozilla / 5.0 (Windows NT 6.1; WOW64)AppleWebKit / 537.17(KHTML,像> Gecko)Chrome / 24.0.1312.57 Safari / 537.17“
提前致谢,
它看起来像你正在尝试创build一个正常的转发代理,而不是一个反向代理。 不幸的是,正如你已经发现的那样,nginx不适合作为转发代理工作。 相反,使用专为此目的devise的软件,如squid或wwwoffle。