环境:
阿里云平台:

SLB:111.111.111.100:8001 映射>  ECS Nginx:10.10.10.100:80 反向代理> Tomcat:127.0.0.1:8080
域名解析: test.xxxx.com.cn > 111.111.111.100

ECS服务器配置:
Nginx:(80端口)
配置文件

server {
    listen       80;
    server_name  test.xxxx.com.cn;
    access_log  logs/test-access.log  main;
    error_log   logs/test-error.log;
    location / {
        proxy_pass      http://127.0.0.1:8080;
        #root   html;
        #index  index.html index.htm;
   	}
}

tomcat(8080端口)
配置文件:默认tomcat配置信息
应用路径:$tomcat_home/webapps/test-app
测试:
完成以上配置后,浏览器测试访问http://test.xxxx.com.cn:8001/test-app,无法访问,且浏览器url被重置为http://test.xxxx.com.cn/test-app/login

抓包跟踪检查,发现Request URL: http://test.xxxx.com.cn:8001/test-app,
但Response Headers中Location: http://test.xxxx.com.cn/test-app

处理:
修改nginx.conf配置文件

server {
    listen       80;
    server_name  test.xxxx.com.cn;
    access_log  logs/test-access.log  main;
    error_log   logs/test-error.log;
    location / {
        proxy_pass      http://127.0.0.1:8080;
        proxy_set_header Host $host:8001;  #这里修改为SLB监听的端口号
        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;
        #root   html;
        #index  index.html index.htm;
    }
}

重启Nginx服务

# /home/nginx/sbin/nginx -s reload

再次访问http://test.xxxx.com.cn:8001/test-app,正常访问。
记一次nginx重定向端口问题

相关文章:

  • 2021-12-27
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2021-09-02
  • 2022-01-30
猜你喜欢
  • 2022-02-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
  • 2021-07-04
  • 2022-12-23
相关资源
相似解决方案