{"id":1198,"date":"2017-03-05T19:56:07","date_gmt":"2017-03-05T14:26:07","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=1198"},"modified":"2017-03-05T19:56:07","modified_gmt":"2017-03-05T14:26:07","slug":"redirect-http-https-nginx-behind-load-balancers","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/redirect-http-https-nginx-behind-load-balancers\/","title":{"rendered":"Redirect http to https on nginx behind load balancers"},"content":{"rendered":"<p><strong>Date Posted:05-03-2015<\/strong><\/p>\n<p>This post explains on how to redirect all http request to https on nginx server which are behind load balancer.<\/p>\n<h5>Assumption:<\/h5>\n<ol>\n<li>Ubuntu or Centos<\/li>\n<li>Nginx Webserver- If nginx is not installed on the serer, refer the following <a href=\"https:\/\/pheonixsolutions.com\/blog\/install-nginx-php-mariadb-ubuntu-16-04-1\/\">URL<\/a> to install.<\/li>\n<\/ol>\n<h5>Implementation:<\/h5>\n<p>Let&#8217;s assume that the server has only one website and the configuration location is\u00a0<em>\/etc\/nginx\/site-enabled\/default.<\/em><\/p>\n<p>Open the configuration and append the following section under\u00a0<span style=\"color: #ff6600;\"><em>server\u00a0<\/em> <\/span>blocks.<\/p>\n<p><code>vi \/etc\/nginx\/sites-enabled\/default<\/code><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">if ($http_x_forwarded_proto != 'https') {\r\n rewrite ^(.*) https:\/\/$host$1 permanent;\r\n}<\/pre>\n<p>Where,<\/p>\n<p>$http_x_forwarded_proto &#8211; &gt;This refer to origin request or client request<\/p>\n<p>!=https -&gt; If the request is Not Equal to https<br \/>\nrewrite -&gt; Rewrite rule<\/p>\n<p>https:\/\/$host$1 &#8211; Redirects the request to https<\/p>\n<p>Verify the syntax of the nginx configuration.<\/p>\n<p><code>nginx -t<\/code><\/p>\n<p>Restart the service to make changes into effect.<\/p>\n<p><code>\/etc\/init.d\/nginx reload<\/code><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Date Posted:05-03-2015 This post explains on how to redirect all http request to https on nginx server which are behind [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_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","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[],"class_list":["post-1198","post","type-post","status-publish","format-standard","hentry","category-web-architecture","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-jk","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=1198"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1198\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}