Cloudflare Page Rule for HTTP to HTTPS

As many are aware, aMi STACX is big on “It just works!” configurations. Why spend hours trying to hack to make something as simple as http to https redirection work? Although if you use Let’s Encrypt on our LAMP stacks, and select option 2 as we suggest, then the redirection is done for you. Sweet!

Yet, if you’re using one of our NGINX LEMP stacks with Let’s Encrypt there is no Option 2. Messing with the NGINX vhost default configuration is also a little less friendly for those familiar with Apache vhost redirection configurations, but new to the NGINX world. So to keep with our mantra of simplicity we suggest a very sly solution.

As we also advocate Cloudflare for DNS and CDN solutions for those that just want to get up and running as quick as possible in a user friendly GUI format, Cloudflare also happens to offer a solution to assist in addressing the complexity of HTTP to HTTPS on our NGINX LEMP stacks.

Cloudflare offers two ways to accomplish this task. One is through their Always Use HTTPSfeature in the Crypto section on your Cloudflare Dashboard. The second option is by setting up a page rule. Page rules offer a lot more granular control of the HTTP to HTTPS redirection. You can even use advanced pattern matching.

There is a benefit of speed when taking advantage of the CDN, as the redirection takes place at the edge and offloads the processing from the local AWS EC2 server.

The “Always use HTTPS” action in the above Cloudflare dashboard graphic is the simplest option to redirect HTTP requests to HTTPS. The example shown will redirect all requests for example.com to HTTPS, but you can use any valid pattern to limit this action to a specific subdomain or directory.

More on Cloudflare Page Rules >>

Cloudflare Page Rules – wildcard matches >>

Better – Stronger – Faster!

Leave a Reply