{"id":2984,"date":"2020-04-04T18:11:12","date_gmt":"2020-04-04T12:41:12","guid":{"rendered":"https:\/\/www.24x7serversupport.com\/blog\/?p=2984"},"modified":"2020-04-04T18:11:37","modified_gmt":"2020-04-04T12:41:37","slug":"how-to-force-redirect-to-https-behind-aws-elb","status":"publish","type":"post","link":"https:\/\/www.24x7serversupport.com\/blog\/how-to-force-redirect-to-https-behind-aws-elb\/","title":{"rendered":"How To Force Redirect To HTTPS behind AWS ELB"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<p>Here we will use X-Forwarded-Proto header value of the HTTP request, and apply the rewrite rules if the client protocol is not HTTPS.<\/p>\n\n\n\n<p>Below are the configurations for Apache, Nginx and IIS to force redirect to HTTPS behind AWS ELB.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">APACHE<\/h2>\n\n\n\n<p>Make sure to enable rewrite module for apache. Edit the VirtualHost conf in a text editor and add following contents:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;VirtualHost *:80&gt;\n  ...\n  RewriteEngine On\n  RewriteCond %{HTTP:X-Forwarded-Proto} !https\n  RewriteRule ^.*$ https:\/\/%{SERVER_NAME}%{REQUEST_URI}\n&lt;\/VirtualHost&gt;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">NGINX<\/h2>\n\n\n\n<p>Edit the HTTP server block in your domain&#8217;s configuration and add below contents:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">server {\n listen 80;\n ...\n location \/ {\n  if ($http_x_forwarded_proto != 'https') {\n  rewrite ^ https:\/\/$host$request_uri? permanent;\n  }\n }\n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">IIS<\/h2>\n\n\n\n<p>The windows servers with IIS web server edit the web.config file and add the following code under the section:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;rewrite>\n&lt;rules>\n&lt;rule name=\"Force Redirect to HTTPS\" stopProcessing=\"true\">\n&lt;match url=\"^(.*)$\" ignoreCase=\"false\" \/>\n&lt;conditions>\n&lt;add input=\"{HTTP_X_FORWARDED_PROTO}\" pattern=\"^http$\" ignoreCase=\"false\" \/>\n&lt;\/conditions>\n&lt;action type=\"Redirect\" redirectType=\"Found\" url=\"https:\/\/{HTTP_HOST}{REQUEST_URI}\" \/>\n&lt;\/rule>\n&lt;\/rules>\n&lt;\/rewrite><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[34,37],"tags":[119,281,280,144,279],"class_list":["post-2984","post","type-post","status-publish","format-standard","hentry","category-linux","category-windows","tag-apache","tag-elb","tag-iis","tag-nginx","tag-redirect-to-https"],"jetpack_publicize_connections":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Force Redirect To HTTPS behind AWS ELB | 24x7serversupport Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.24x7serversupport.com\/blog\/how-to-force-redirect-to-https-behind-aws-elb\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Force Redirect To HTTPS behind AWS ELB | 24x7serversupport Blog\" \/>\n<meta property=\"og:description\" content=\"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. [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.24x7serversupport.com\/blog\/how-to-force-redirect-to-https-behind-aws-elb\/\" \/>\n<meta property=\"og:site_name\" content=\"24x7serversupport Blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-04T12:41:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-04T12:41:37+00:00\" \/>\n<meta name=\"author\" content=\"24x7support\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@24x7serversuppo\" \/>\n<meta name=\"twitter:site\" content=\"@24x7serversuppo\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"24x7support\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/how-to-force-redirect-to-https-behind-aws-elb\/\",\"url\":\"https:\/\/www.24x7serversupport.com\/blog\/how-to-force-redirect-to-https-behind-aws-elb\/\",\"name\":\"How To Force Redirect To HTTPS behind AWS ELB | 24x7serversupport Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/#website\"},\"datePublished\":\"2020-04-04T12:41:12+00:00\",\"dateModified\":\"2020-04-04T12:41:37+00:00\",\"author\":{\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/#\/schema\/person\/decfb5fad6bde6ac6822d4e965c6d401\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/how-to-force-redirect-to-https-behind-aws-elb\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.24x7serversupport.com\/blog\/how-to-force-redirect-to-https-behind-aws-elb\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/how-to-force-redirect-to-https-behind-aws-elb\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.24x7serversupport.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Force Redirect To HTTPS behind AWS ELB\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/#website\",\"url\":\"https:\/\/www.24x7serversupport.com\/blog\/\",\"name\":\"24x7serversupport Blog\",\"description\":\"Linux | CPanel | WHM | webhosting| Plesk | DirectAdmin | CentOs | Debian | Ubuntu Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.24x7serversupport.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.24x7serversupport.com\/blog\/#\/schema\/person\/decfb5fad6bde6ac6822d4e965c6d401\",\"name\":\"24x7support\",\"url\":\"https:\/\/www.24x7serversupport.com\/blog\/author\/24x7support\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Force Redirect To HTTPS behind AWS ELB | 24x7serversupport Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.24x7serversupport.com\/blog\/how-to-force-redirect-to-https-behind-aws-elb\/","og_locale":"en_US","og_type":"article","og_title":"How To Force Redirect To HTTPS behind AWS ELB | 24x7serversupport Blog","og_description":"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. [&hellip;]","og_url":"https:\/\/www.24x7serversupport.com\/blog\/how-to-force-redirect-to-https-behind-aws-elb\/","og_site_name":"24x7serversupport Blog","article_published_time":"2020-04-04T12:41:12+00:00","article_modified_time":"2020-04-04T12:41:37+00:00","author":"24x7support","twitter_card":"summary_large_image","twitter_creator":"@24x7serversuppo","twitter_site":"@24x7serversuppo","twitter_misc":{"Written by":"24x7support","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.24x7serversupport.com\/blog\/how-to-force-redirect-to-https-behind-aws-elb\/","url":"https:\/\/www.24x7serversupport.com\/blog\/how-to-force-redirect-to-https-behind-aws-elb\/","name":"How To Force Redirect To HTTPS behind AWS ELB | 24x7serversupport Blog","isPartOf":{"@id":"https:\/\/www.24x7serversupport.com\/blog\/#website"},"datePublished":"2020-04-04T12:41:12+00:00","dateModified":"2020-04-04T12:41:37+00:00","author":{"@id":"https:\/\/www.24x7serversupport.com\/blog\/#\/schema\/person\/decfb5fad6bde6ac6822d4e965c6d401"},"breadcrumb":{"@id":"https:\/\/www.24x7serversupport.com\/blog\/how-to-force-redirect-to-https-behind-aws-elb\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.24x7serversupport.com\/blog\/how-to-force-redirect-to-https-behind-aws-elb\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.24x7serversupport.com\/blog\/how-to-force-redirect-to-https-behind-aws-elb\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.24x7serversupport.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How To Force Redirect To HTTPS behind AWS ELB"}]},{"@type":"WebSite","@id":"https:\/\/www.24x7serversupport.com\/blog\/#website","url":"https:\/\/www.24x7serversupport.com\/blog\/","name":"24x7serversupport Blog","description":"Linux | CPanel | WHM | webhosting| Plesk | DirectAdmin | CentOs | Debian | Ubuntu Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.24x7serversupport.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.24x7serversupport.com\/blog\/#\/schema\/person\/decfb5fad6bde6ac6822d4e965c6d401","name":"24x7support","url":"https:\/\/www.24x7serversupport.com\/blog\/author\/24x7support\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/posts\/2984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/comments?post=2984"}],"version-history":[{"count":1,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/posts\/2984\/revisions"}],"predecessor-version":[{"id":2985,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/posts\/2984\/revisions\/2985"}],"wp:attachment":[{"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/media?parent=2984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/categories?post=2984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.24x7serversupport.com\/blog\/wp-json\/wp\/v2\/tags?post=2984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}