top of page

HTTP to HTTPs redirection in an AWS Lightsail Bitnami Server

By: Shibily Shukoor

Scenario:

Although configuring an SSL certificate in the AWS Light sail environment allows you to access the hosted website using https:// protocol, the protocol is not used by default. To make sure that the website is accessed only using the https:// protocol, you will need to set up an automatic redirect so that you want to force people coming to your website to use the HTTPS.


If you are a website owner or system administrator, chances are that you’re dealing with Apache on a regular basis. One of the most common tasks you’ll likely perform is redirecting the HTTP traffic to the secured (HTTPS) version of your website.


There are many advantages of using HTTPS over HTTP, they are:

  1. One of the main benefits of HTTPS is that it adds security and trust. It protects users against man-in-the-middle (MitM) attacks that can be launched from compromised or insecure networks.

  2. Google Chrome and all other popular browsers will mark your website as safe.

  3. HTTPS allows you to use the HTTP/2 protocol, which significantly improves the site performance.

  4. Google favors HTTPS websites. Your site will rank better if served via HTTPS.

This guide covers how to redirect HTTP traffic to HTTPS in an AWS LightSail environment. There are many forums that are discussing this issue, I thought it would be worthwhile to document encountered and the solution that worked.


Solution:

Note: Before you can set up an Apache redirect from http to https, you will need to do the following:

  • Ensure your SSL certificate is successfully installed, so you can accesshttps://www.yoursite.com (for more information, see the AWS SSL Installation Instructions)

  • Ensure mod_rewrite is enabled in Apache.

We @Snapblocs directly tried help document from Bitnami to force HTTPS in our website only to see too many redirects’ error in the browser. We noticed the Bitnami solution is redirecting the website multiple times.

Configure the web server behind the Classic Load Balancer to use the X-Forwarded-Proto header to direct traffic based on whether clients use HTTP or HTTPS. Be sure to add rewrite rules to your web servers that:

  • Redirect clients using HTTP to an HTTPS URL

  • Serve clients using HTTPS directly

Steps:

  1. Open your Apache configuration file in the Bitnami Server. Location:/opt/bitnami/apache2/conf/bitnami/bitnami.conf

  2. Add a rewrite rule to the <VirtualHost _default_:80> section of your configuration file, similar to the following:

RewriteEngine On RewriteCond %{HTTP:X-Forwarded-Proto} =http RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

3. Save your Apache configuration file.

4. Restart Apache.

apachectl restart

References:

  1. https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/


50 views
bottom of page