2

I'm configuring HAProxy to redirect http to https, but it doesn't seem to work. The configuration I use is:

/etc/hosts content

127.0.0.1 example.com

Haproxy configuration

frontend http
  mode http
  bind :80
  bind :443 ssl crt /etc/ssl/
  redirect scheme https if !{ ssl_fc }

  default_backend my_backend

Testing with curl give this error

$ curl https://example.com < this works 
$ curl http://example.com 
> curl: (7) Failed to connect to 2400:cb00:2048:1::681c:a20: No route to host

However, command lsof has output

$ sudo lsof -i :80 | grep LISTEN
haproxy   7290 root    4u  IPv4 0x9485b36892b5495d      0t0  TCP *:http (LISTEN)

I'm out of idea what's wrong in this situation. This is the first time I configure SSL on Haproxy.

4
  • @masegaloeh thanks for pointing out. You are correct, but when I try to connect via ipv4, I has this curl: (7) couldn't connect to host Dec 16, 2014 at 8:02
  • what version of haproxy are you running?
    – Jim G.
    Dec 17, 2014 at 17:49
  • @JimG. The HAproxy version I use is : HA-Proxy version 1.5.3 2014/07/25 Dec 18, 2014 at 6:03
  • Do you get an error on http in a browser?
    – Jim G.
    Dec 18, 2014 at 18:37

1 Answer 1

1

I have a very similar set up in HAProxy which works. I can only find two differences between your configuration and mine.

  1. In /etc/hosts I have bound example.com to 0.0.0.0 rather than 127.0.0.1.
  2. In my frontend, both bind entries contain a wildcard (*) in front of the colon. Example:

    bind *:80
    bind *:443 ssl crt /etc/ssl/ssl.pem
    

    2a. I actually used a pem file in my configuration (as above) but seeing as curl https://example.com worked it is unlikely this is the problem.

I would also suggest looking at the output of netstat -tulpn | grep haproxy for more detail on where HAProxy is binding.

Hope that helps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .