Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»AWS»How To Force Redirect To HTTPS behind AWS ELB

    How To Force Redirect To HTTPS behind AWS ELB

    RahulBy RahulMarch 4, 20182 Mins ReadUpdated:March 6, 2018

    Your web server is running on port 80 to listen http connections on AWS Ec2 instnace. After that configured AWS ELB to listen on HTTP and HTTPS protocols and forwarding all the requests to backend server on port 80 only. The Amazon Elastic Load Balancer (ELB) supports X-Forwarded-Proto header value include the protocol of application.

    This tutorial uses X-Forwarded-Proto header value of the HTTP request, and apply the rewrite rules if the client protocol is not HTTPS. Here is the configuration details for Apache, Nginx and IIS to force redirect to HTTPS behind AWS ELB .

    1. Apache

    Edit Apache VirtualHost configuration file in text editor and add the following content. Make sure rewrite module is enabled in Apache server.

    <VirtualHost *:80>
      ...
      RewriteEngine On
      RewriteCond %{HTTP:X-Forwarded-Proto} !https
      RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI}
    </VirtualHost>
    

    2. Nginx

    Edit Nginx HTTP server block for your domain to configure force redirection. Add the following content under location block to redirect all http traffic to https.

    server {
     listen 80;
     ...
     location / {
      if ($http_x_forwarded_proto != 'https') {
      rewrite ^ https://$host$request_uri? permanent;
      }
     }
    }
    

    3. IIS

    The windows servers with IIS web server edit the web.config file and add the following code under the section:

    <rewrite>
    <rules>
    <rule name="AWS ELB Forece Redirect to HTTPS" stopProcessing="true">
    <match url="^(.*)$" ignoreCase="false" />
    <conditions>
    <add input="{HTTP_X_FORWARDED_PROTO}" pattern="^http$" ignoreCase="false" />
    </conditions>
    <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />
    </rule>
    </rules>
    </rewrite>
    
    aws ec2 elb https SSL
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Upgrade Ubuntu 16.04 to Ubuntu 18.04 LTS
    Next Article How to Install NoMachine on Ubuntu, Debian and LinuxMint (Alternative of TeamViewer)

    Related Posts

    How to Delete a Let’s Encrypt Certificate using Certbot

    Updated:June 3, 20222 Mins Read

    Backup MySQL Databases to Amazon S3 (Shell Script)

    Updated:May 28, 20222 Mins Read

    How to Install and Secure Apache on Debian11

    6 Mins Read

    How to Remove CloudFront Cache

    Updated:April 3, 20212 Mins Read

    How To Secure Tomcat with Let’s Encrypt SSL

    Updated:June 4, 20223 Mins Read

    Python Script to Create CloudFront Invalidations

    2 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How To Install Docker on Ubuntu 22.04
    • How to Install Bower on Ubuntu 22.04 & 20.04
    • How to run “npm start” through Docker
    • Filesystem Hierarchy Structure (FHS) in Linux
    • How to accept user input in Python
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.