HAProxy redirecting http to https (ssl)

前端 未结 16 1440
你的背包
你的背包 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:53

    I found this to be the biggest help:

    Use HAProxy 1.5 or newer, and simply add the following line to the frontend config:

    redirect scheme https code 301 if !{ ssl_fc }
    
    0 讨论(0)
  • 2020-12-22 22:56
    frontend unsecured *:80
        mode http
        redirect location https://foo.bar.com
    
    0 讨论(0)
  • 2020-12-22 22:56

    Add this into the HAProxy frontend config:

    acl http      ssl_fc,not
    http-request redirect scheme https if http
    

    HAProxy - Redirecting HTTP Requests

    0 讨论(0)
  • 2020-12-22 23:02

    Why don't you use ACL's to distinguish traffic? on top of my head:

    acl go_sslwebserver path bar
    use_backend sslwebserver if go_sslwebserver
    

    This goes on top of what Matthew Brown answered.

    See the ha docs , search for things like hdr_dom and below to find more ACL options. There are plenty of choices.

    0 讨论(0)
  • 2020-12-22 23:03

    The best guaranteed way to redirect everything http to https is:

    frontend http-in
       bind *:80
       mode http
       redirect scheme https code 301
    

    This is a little fancier using ‘code 301′, but might as well let the client know it’s permanent. The ‘mode http’ part is not essential with default configuration, but can’t hurt. If you have mode tcp in defaults section (like I did), then it’s necessary.

    0 讨论(0)
  • 2020-12-22 23:05

    In newer versions of HAProxy it is recommended to use

    http-request redirect scheme https if !{ ssl_fc }
    

    to redirect http traffic to https.

    0 讨论(0)
提交回复
热议问题