HAProxy redirecting http to https (ssl)

前端 未结 16 1460
你的背包
你的背包 2020-12-22 22:04

I\'m using HAProxy for load balancing and only want my site to support https. Thus, I\'d like to redirect all requests on port 80 to port 443.

How would I do this?<

16条回答
  •  执念已碎
    2020-12-22 22:49

    According to http://parsnips.net/haproxy-http-to-https-redirect/ it should be as easy as configuring your haproxy.cfg to contain the follow.

    #---------------------------------------------------------------------
    # Redirect to secured
    #---------------------------------------------------------------------
    frontend unsecured *:80
        redirect location https://foo.bar.com
    
    #---------------------------------------------------------------------
    # frontend secured
    #---------------------------------------------------------------------
    frontend  secured *:443
       mode  tcp
       default_backend      app
    
    #---------------------------------------------------------------------
    # round robin balancing between the various backends
    #---------------------------------------------------------------------
    backend app
        mode  tcp
        balance roundrobin
        server  app1 127.0.0.1:5001 check
        server  app2 127.0.0.1:5002 check
        server  app3 127.0.0.1:5003 check
        server  app4 127.0.0.1:5004 check
    

提交回复
热议问题