由于Haproxy是通过 url 正则匹配 识别 的,nginx代理到 haproxy需要设置 

proxy_set_header Host 为 haproxy的目标 url

直接上配置

upstream xxx03_api_haproxy {
    server xxx03.api.xxx.com;
}
upstream xxx03_443_api_haproxy {
    server xxx03.api.xxx.com:443;
}

server {
   listen 80;
   #server_name xxx03.api.xxx.com;
   location / {
           proxy_pass http://xxx03_api_haproxy;
           proxy_set_header Host xxx03.api.xxx.com;
           proxy_redirect off;
   }
}

#server {
#   listen 80;
#   server_name xxx03.test.xxx.com;
#   location / {
#           proxy_pass https://xxx03_443_api_haproxy;
#           proxy_set_header Host xxx03.test.xxx.com;
#           proxy_redirect off;
#   }
#}

server {
    listen 443;
    #server_name xxx03.test.xxx.com;
    ssl on;
    ssl_certificate /etc/nginx/conf.d/server.cert;
    ssl_certificate_key /etc/nginx/conf.d/server.key;
    location / {
           proxy_pass https://xxx03_443_api_haproxy;
           proxy_set_header Host xxx03.test.xxx.com;
           proxy_redirect off;
   }
}

 

相关文章:

  • 2022-02-05
  • 2021-12-10
  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2021-07-14
相关资源
相似解决方案