haproxy + nginx: https trailing slashes redirected to http
Posted
by
user1719907
on Server Fault
See other posts from Server Fault
or by user1719907
Published on 2012-10-04T13:05:13Z
Indexed on
2012/10/09
21:44 UTC
Read the original article
Hit count: 207
I have a setup where HTTP(S) traffic goes from HAProxy to nginx.
HAProxy nginx
HTTP -----> :80 ----> :9080
HTTPS ----> :443 ----> :9443
I'm having troubles with implicit redirects caused by trailing slashes going from https to http, like this:
$ curl -k -I https://www.example.com/subdir
HTTP/1.1 301 Moved Permanently
Server: nginx/1.2.4
Date: Thu, 04 Oct 2012 12:52:39 GMT
Content-Type: text/html
Content-Length: 184
Location: http://www.example.com/subdir/
The reason obviously is HAProxy working as SSL unwrapper, and nginx sees only http requests. I've tried setting up the X-Forwarded-Proto to https on HAProxy config, but it does nothing.
My nginx setup is as follows:
server {
listen 127.0.0.1:9443;
server_name www.example.com;
port_in_redirect off;
root /var/www/example;
index index.html index.htm;
}
And the relevant parts from HAProxy config:
frontend https-in
bind *:443 ssl crt /etc/example.pem prefer-server-ciphers
default_backend nginxssl
backend nginxssl
balance roundrobin
option forwardfor
reqadd X-Forwarded-Proto:\ https
server nginxssl1 127.0.0.1:9443
© Server Fault or respective owner