Nodebalancer SSL and URL Redirects
We have setup 2 port configurations under our NodeBalancer. 1 for http traffic running through port 80, and another for HTTPS traffic running through port 443.
Both port configurations connect to the same Linode on port 80. We have SSL connections terminating at the Nodebalancer.
In our virtualhost config for the Linode we have the following rewrite rules (there's obviously a lot more setup in there regarding serverName, DocumentRoot etc) so for brevity here's the rewrite rules only.
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,L]
We would like all traffic to end at the URL
For http traffic, those rewrite rules remove the www. part of the host and point the url through to https.
This works great for the following URLs:
–
–
This URL just works:
–
However the following URL does NOT redirect properly (notice it doesn't end at https):
–
I realise that the redirect rule is only affecting connections made with a www. but I can't figure out how to redirect all traffic through to https without there being a infinite redirect loop occurring. I believe this is because all connections between the NodeBalanacer and the Linode are http only. I'd be happy to write specific rewrite rules under a
Does anyone have any smart redirect rules that could work under this circumstance? Or do I need to setup the Nodebalancer to pass on the SSL termination directly to the Lindoes themselves by connecting over port 443 using just a TCP connection?
Many thanks,
1 Reply
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} ^http$
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [L,R=301]
Based on
If HTTP or HTTPS is selected, the NodeBalancer will add an X-Forwarded-Proto header, with a value of either http or https, to all requests sent to the backend. The header value is based on the type of request (HTTP or HTTPS) originally received by the NodeBalancer.