nginx使用非80端口时url带端口号的解决办法
在nginx中配置server侦听非80端口时,我们在访问时会在url中加入对应的端口号,如:http://xxx.xxx.xxx:8006/,但如果在nginx服务器前有另一台服务器作为用户首先访问的web服务器,这台服务器设置了端口转发,将80端口获得的请求转发到nginx中的对应端口中,如8006,这时用户使用的url是没有端口号,但nginx会自动增加端口号到url上,很可能导致用户访问失败,可以将location 中增加proxy_set_header Host $host,即可解决此问题(在实际工作遇到,特此记下)
点赞 1
————————————————
版权声明:本文为CSDN博主「可能青蛙」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/hejun1218/article/details/73385437
在做Nginx反向代理时遇到个很烦人的问题,总是要显示端口号,查找了下终于找到解决办法
server {
listen 80;
server_name localhost;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://127.0.0.1:8080/;
}
}
proxy_set_header Host $host:$server_port; 这段比较关键之前我没加$server_port就老是到下级请求出现真实端口号。
点赞 1
————————————————
版权声明:本文为CSDN博主「愤怒的苹果ext」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/baidu_19473529/article/details/53932300
nginx 反向代理 解决非80端口映射
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | 写法一: http { include mime.types; default_type application/octet-stream; sendfile on ; keepalive_timeout 65; #此处可以解决负载均衡问题 upstream portalTest { server www.ceshitest.com:8089 weight=5; #server 192.168.0.102:8001 weight=2; } server { listen 80; server_name www.ceshitest.com; proxy_redirect off; # nginx非80端口处理 proxy_set_header Host $host:$server_port; # 获取真实IP #proxy_set_header X-Real-IP $remote_addr; # 获取代理者的真实ip #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; location / { proxy_pass http: //portalTest; } } } <pre name= "code" class = "html" >写法二: http { include mime.types; default_type application/octet-stream; sendfile on ; keepalive_timeout 65; server { listen 80; server_name www.ceshitest.com; location / { proxy_pass http: //<span style="font-family: Arial, Helvetica, sans-serif;">www.ceshitest.com:8089</span><span style="font-family: Arial, Helvetica, sans-serif;">;</span> } } } ———————————————— 版权声明:本文为CSDN博主「笑面依旧」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。 原文链接:https: //blog.csdn.net/OXiaoMianYiJiu/article/details/51263476 |
nginx做非80端口转发
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | nginx可以很方便的配置成反向代理服务器 server { listen 80; server_name localhost; location / { proxy_pass http: //147.16.24.175:9500 ; proxy_set_header Host $host:80; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Via "nginx" ; } } 但是如果nginx的监听端口不是默认的80端口,改为其他端口如81端口。 后端服务器中request.getServerPort()无法获得正确的端口,返回的仍然是80; 在response.sendRedirect()时,客户端可能无法获得正确的重定向url。 正确的配置方法为 在 $host之后加上端口号,如$host:81 server { listen 83; server_name localhost; location / { proxy_pass http: //147.16.24.175:9500 ; proxy_set_header Host $host:83; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Via "nginx" ; } } ============== ———————————————— 版权声明:本文为CSDN博主「风月无边」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。 原文链接:https: //blog.csdn.net/xzknet/article/details/6342018 |
nginx监听非80端口时转发端口不正确问题
今天部署项目的时候碰到这样一个问题,对方服务器80端口不对外开放仅开放一个6659端口映射内网8080端口,因为不只一个地方需要8080端口因此需要nginx做代理,一开始nginx.conf配置是这样的:
这样配置项目部署之后碰到一个问题,静态资源无法访问,F12之后发现所有资源都请求到了8080端口(Tomcat里端口是8081),于是继续修改nginx配置如下:
重启nginx,项目运行成功。
————————————————
版权声明:本文为CSDN博主「zch1990s」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zch1990s/article/details/79035659
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步