
环境:
IIS:127.0.0.1,监听9800端口
:监听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. 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,这样访问就没有问题啦。
胜象大百科







