【Nginx】nginx 代理 Haproxy 怎么设置?

时间:2023-03-10 04:26:55
【Nginx】nginx 代理 Haproxy 怎么设置?

由于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:;
} server {
listen ;
#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 ;
# 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 ;
#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;
}
}