【发布时间】:2014-11-11 13:08:48
【问题描述】:
我有两个 web 应用程序在两个独立的 docker 容器内的服务器上运行,其中一个在 play framework 服务器 (java) 上运行,而另一个在 nginx (php) 上运行。我正在 haproxy 为 play 应用程序以 http 模式执行 ssl 终止。我想在 nginx 处理其他应用程序的 ssl 终止。 是否可以通过这种方式配置 haproxy,使一个前端以 tcp 模式转发请求,另一个以 http 模式转发请求。下面是我的 haproxy.cfg 的样子。
frontend http-in
mode http
bind *:80
redirect scheme https code 301 if !{ ssl_fc }
frontend https-in
# bind *:80
bind *:443 ssl crt /etc/ssl/certs/my_certificate_file.pem
reqadd X-Forwarded-Proto:\ https
# redirect scheme https code 301 if !{ ssl_fc }
mode http
option httpclose
option forwardfor
# Define hosts based on domain names
acl host_test_ssh hdr(host) -i playapp.domain.com
## figure out backend to use based on domainname
use_backend testssh if host_test_ssh
frontend http-in-other
bind *:80
mode tcp
option tcplog
redirect scheme https if !{ ssl_fc }
frontend https-in-estore
bind *:443
mode tcp
option tcplog
# Define hosts based on domain names
acl host_test_ssh hdr(host) -i nginxapp.domain2.com
## figure out backend to use based on domainname
use_backend other if host_test_ssh
【问题讨论】:
-
您在 tcp 模式下有一个“https-in-estore”,但尝试读取“Host”HTTP 标头(“hdr(host)”) - 这将不起作用,因为 haproxy 将忽略任何 HTTP tcp 模式下的标头。有关更多指导,请参阅serverfault.com/a/561493/147771
标签: nginx load-balancing docker haproxy