目前有一個需求,生產ip爲 http://pro.com,開發ip爲 http://dev.com,當請求生產服務器出錯時,將請求發送到開發服務器,從開發服務器中獲取數據。
獲取錯誤代碼必須配置這一項:
proxy_intercept_errors on;
代理轉發配置:
error_page 404 @error;
location @error {
return 307 http://dev.com$uri?$args;
}
完整的配置如下:
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
fastcgi_intercept_errors on;
proxy_intercept_errors on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
listen 8080;
server_name 127.0.0.1;
proxy_connect_timeout 1200s;
proxy_send_timeout 1200s;
proxy_read_timeout 1200s;
proxy_set_header Host $host:$server_port;
location / {
proxy_pass http://pro.com;
}
error_page 404 @error;
location @error {
return 307 http://dev.com$uri?$args;
}
}
}