環境:
IIS:127.0.0.1,監聽9800端口
Nginx:監聽80端口
nginx反向代理IIS時,服務端會返回Location,而Location中的地址恰巧是域名+9800(IIS監聽的端口),會進行重定向,導致訪問域名時會自動跳轉到http://www.aaa.com:9800/Index.aspx。
Location
那么就出現了訪問出錯的問題
那這個問題如何解決呢?可以在nginx反向代理上做處理
如下:
修改Header
通過內置的操作,修改header分為兩步,先將其刪除再增加。
例如:
fastcgi_hide_header Location;
proxy_hide_header Location;
add_header Location 'http://www.aaa.com/Index.aspx';
upstream www.aaa.com {
server 127.0.0.1:9800;
}
server {
listen 80;
server_name www.aaa.com;
server_tokens off;
charset utf-8;
location ~ ^/webticket/WEB-INF/{
deny all;
}
location /{
fastcgi_hide_header Location;
proxy_hide_header Location;
add_header Location 'http://www.aaa.com/Index.aspx';
proxy_pass http://www.aaa.com;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
index index.html index.htm index.jsp;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
這樣操作,會先把原來的Location:http://www.aaa.com:9800/Index.aspx刪除,然后再添加一個Location:http://www.aaa.com/Index.aspx,這樣訪問就沒有問題啦。






