nginx 反向代理 端口设置问题

来源:互联网 发布:mac虚拟机安装win7 编辑:程序博客网 时间:2024/05/21 08:46
nginx可以很方便的配置成反向代理服务器


server {


listen 80;


server_name bothlog.com;


location / {


proxy_set_header Host $host;


proxy_set_header X-Forwarded-For $remote_addr;


proxy_pass http://127.0.0.1:9380;


}


}


但是如果nginx的监听端口不是默认的80端口,改为其他端口如81端口。


后端服务器中request.getServerPort()无法获得正确的端口,返回的仍然是80;


在response.sendRedirect()时,客户端可能无法获得正确的重定向url。


正确的配置方法为


在 $host之后加上端口号,如$host:81


server {


listen 81;


server_name bothlog.com;


location / {


proxy_set_header Host $host:81;


proxy_set_header X-Forwarded-For $remote_addr;


proxy_pass http://127.0.0.1:9380;


}


}
0 0
原创粉丝点击