haproxy - 如何进行虚拟主机和https转发?

时间:2014-09-09 08:24:16

标签: ssl proxy routes centos haproxy

任何人都可以建议如何使用haproxy做到这一点?

我有这个haproxy设置,我得到https请求并将其重定向到localhost 8888。 但现在我有更多的请求我需要应用虚拟主机

https://python.stackoverflow.com = goes to as it is http://localhost:8888
https://cplusplus.stackoverflow.com = goes to /var/www/html/cgi-project
https://chat.stackoverflow.com = goes to /var/www/html/microchat
https://zendframework.stackoverflow.com = goes to /var/www/html/zf2/public

global
    log 127.0.0.1 local0 debug
    maxconn 8000
    user    haproxy
    group   haproxy
defaults
    log     global
    option  httplog
    option  dontlognull
    option  http-server-close
    option  redispatch
    retries 3
    mode    http
    maxconn         5000
    timeout connect  5s
    timeout client  30s
    timeout server  30s
    timeout tunnel  12h
frontend www
    bind     :8881
    option   forwardfor
    redirect scheme https if !{ ssl_fc }
frontend lb
    bind   :8882 ssl crt /etc/stunnel/all.pem ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-RC4-SHA:ECDHE-RSA-RC4-SHA:ECDH-ECDSA-RC4-SHA:ECDH-RSA-RC4-SHA:ECDHE-RSA-AES256-SHA:RC4-SHA
    option forwardfor
    reqadd X-Forwarded-Proto:\ https
    default_backend  api
    acl is_websocket hdr(Upgrade)  -i WebSocket
    acl is_websocket hdr_beg(Host) -i ws
    acl is_api       hdr_beg(Host) -i api
    use_backend ws  if is_websocket
    use_backend api if is_api
backend api
    balance roundrobin
    server  service 127.0.0.1:8888 weight 1 maxconn 2500 check
backend ws
    balance roundrobin
    server  service 127.0.0.1:8888 weight 1 maxconn 2500 check

1 个答案:

答案 0 :(得分:3)

global
    log 127.0.0.1 local0 debug
    maxconn 8000
    user    haproxy
    group   haproxy
defaults
    log     global
    option  httplog
    option  dontlognull
    option  http-server-close
    option  redispatch
    retries 3
    mode    http
    maxconn         5000
    timeout connect  5s
    timeout client  30s
    timeout server  30s
    timeout tunnel  12h
frontend www
    bind     :8881
    option   forwardfor
    redirect scheme https if !{ ssl_fc }
frontend lb
    bind   :443 ssl crt /etc/stunnel/all.pem ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-RC4-SHA:ECDHE-RSA-RC4-SHA:ECDH-ECDSA-RC4-SHA:ECDH-RSA-RC4-SHA:ECDHE-RSA-AES256-SHA:RC4-SHA
    option forwardfor
    reqadd X-Forwarded-Proto:\ https
    default_backend  api
    acl is_websocket hdr(Upgrade)  -i WebSocket
    acl is_websocket hdr_beg(Host) -i ws
    acl is_api       hdr_beg(Host) -i api
    acl subdomain    hdr(host) subdomain.domain.com
    use_backend ws  if is_websocket
    use_backend api if is_api
    use_backend sub if subdomain
backend api
    balance roundrobin
    server  service 127.0.0.1:8888 weight 1 maxconn 2500 check
backend ws
    balance roundrobin
    server  service 127.0.0.1:8888 weight 1 maxconn 2500 check
backend sub
    balance roundrobin
    server  service 127.0.0.1:3000 weight 1 maxconn 2500 check