Nginxnginx 代理 Haproxy 怎么设置?

Posted junneyang 的博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginxnginx 代理 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: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;
   }
}

 

以上是关于Nginxnginx 代理 Haproxy 怎么设置?的主要内容,如果未能解决你的问题,请参考以下文章

NginxNginx基础操作

NginxNginx基础操作

NginxNginx基础操作

NginxNginx基础操作

LVS Nginx和HAproxy的区别,怎么选择最好

nginxNginx相关概念