1

After editing my haproxy config. All my subdomains are now redirecting to https. I just want my domain.com to redirect to https not my subdomains. How do I stop this? Below is my redirect script.

UPDATED

global

  log /dev/log    local0
  log /dev/log    local1 notice
  chroot /var/lib/haproxy

  user haproxy
  group haproxy
  daemon

  ca-base /ssl
  crt-base /ssl

  ssl-default-bind-ciphers kEECDH+aRSA+AES:kRSA+AES:+AES256:RC4-SHA:!kEDH:!LOW:!EXP:!MD5:!aNULL:!eNULL

defaults

  log global
  mode http

  option  httplog
  option  redispatch
  option  forwardfor
  option  dontlognull
  option  http-server-close

  timeout connect 5s
  timeout client 30s
  timeout server 30s
  timeout tunnel 1h

frontend public-front

  bind *:80
  redirect scheme https if !{ ssl_fc }

  bind *:443 ssl crt domain.com.pem 
  use_backend some-back if { path_beg /somepath/ }

  default_backend default-back

backend some-back

  reqadd X-Forwarded-Proto:\ https
  balance leastconn
  option httpchk GET /somepath
  timeout check 500ms

  server some-back someback.domain.com:443 check-ssl ssl ca-file domain.com.pem inter 500ms

backend default-back

  reqadd X-Forwarded-Proto:\ https
  balance leastconn
  option httpchk GET
  timeout check 500ms

  server default-back 127.0.0.1:8080 check-ssl ssl ca-file domain.com.pem inter 500ms

frontend stats-front

  bind :8888 ssl crt domain.com.pem
  default_backend stats-back

backend stats-back

  stats enable
  stats hide-version
  stats realm Haproxy\ Statistics
  stats uri /statistics
  stats auth admin:password

I use https://domain.com as my homepage, naked or no www, this points to haproxy
I use http://sub.domain.com for other things but this redirects to https after accessing the homepage.

HA-Proxy version 1.5.4 2014/09/02

  • 1
    post whole config file; it is likely matter of context where to re-locate these directives that will be doing the redirect to https – Hrvoje Špoljar Oct 22 '14 at 6:01
0

Remove redirect scheme https if !{ ssl_fc } from your "public-front" frontend and replace it with:

 redirect scheme https if { hdr(Host) -i domain.com } !{ ssl_fc}
 redirect scheme https if { hdr(Host) -i www.domain.com } !{ ssl_fc}

Should do what you want. These URLs would redirect:

www.domain.com/

domain.com/

www.domain.com/someotherdirectory/

domain.com/thisisapage.html

These wouldn't:

www2.domain.com

sub.domain.com

www.sub.domain.com

  • still didnt work :( apparently. any chance you would know how to clear the cached 301s and 302s on browser? – Gene Diaz Oct 24 '14 at 2:32
  • In Chrome, you can open up the developer tools (f11) and clear the cookies and cache. As an alternative, you can also try opening an incognito window. – Jim G. Oct 24 '14 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.