Nodebalancer SSL and URL Redirects

Hello,

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.

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]

RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,L]

We would like all traffic to end at the URL https://churchconnect.io/* whether they've come from http or https, with or without www. in the hostname.

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:

http://www.churchconnect.io » https://churchconnect.io

https://www.churchconnect.io » http://churchconnect.io

This URL just works:

https://churchconnect.io » https://churchconnect.io

However the following URL does NOT redirect properly (notice it doesn't end at https):

http://churchconnect.io » http://churchconnect.io

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 directive but I don't think any connections will ever get there from the NodeBalancer.

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

This should work:

RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} ^http$
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [L,R=301]

Based on http://technosophos.com/2012/08/13/rewr … oxies.html">http://technosophos.com/2012/08/13/rewriting-urls-x-forwarded-proto-and-reverse-proxies.html

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.

https://www.linode.com/docs/platform/no … ence-guide">https://www.linode.com/docs/platform/nodebalancer/nodebalancer-reference-guide

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct