{"id":2363,"date":"2018-09-06T04:15:47","date_gmt":"2018-09-06T11:15:47","guid":{"rendered":"https:\/\/www.cloudinsidr.com\/content\/?p=2363"},"modified":"2018-09-06T04:18:29","modified_gmt":"2018-09-06T11:18:29","slug":"how-to-redirect-all-http-to-https-in-nginx","status":"publish","type":"post","link":"https:\/\/www.cloudinsidr.com\/content\/how-to-redirect-all-http-to-https-in-nginx\/","title":{"rendered":"How to redirect all http to https in NGINX"},"content":{"rendered":"<p>When setting up https on an existing server, you need to provide a redirect for all those visitors arriving via http backlinks. Here is how to do this.<\/p>\n<p><!--more--><\/p>\n<p>Redirects are prone to errors. To avoid setting a redirect for your main server block, divide it into two server blocks: one handling http, the other handling https traffic. Make sure you define\u00a0server_name correctly or nothing will happen. Put your redirect only in the http server block.<\/p>\n<pre>server {\r\nlisten 80;\r\nserver_name www.servername.tld servername.tld;\r\nreturn 301 https:\/\/www.servername.tld$request_uri;\r\n}\r\n\r\nserver {\r\nlisten 443 ssl http2;\r\nserver_name www.servername.tld servername.tld; \r\nroot \/var\/www\/www.servername.tld; index index.html index.htm;\r\n\r\n# here goes your https certificate setup and related directives\r\nssl_certificate \/etc\/letsencrypt\/live\/servername.tld\/fullchain.pem;\u00a0\r\nssl_certificate_key \/etc\/letsencrypt\/live\/servername.tld\/privkey.pem;\u00a0\r\ninclude \/etc\/letsencrypt\/options-ssl-nginx.conf; #see other posts on cloudinsidr.com for details\r\nssl_dhparam \/etc\/letsencrypt\/ssl-dhparams.pem;\u00a0#see other posts on cloudinsidr.com for details\u00a0\r\n\r\n# define your location blocks\r\nlocation \/* { \r\nroot \/var\/www\/www.servername.tld; \r\nindex index.html index.htm; \r\ntry_files $uri $uri\/ ; } \r\n# whatever else you need goes in here\r\n\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>When setting up https on an existing server, you need to provide a redirect for all those visitors arriving via http backlinks. Here is how to do this.<\/p>\n","protected":false},"author":1,"featured_media":2365,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[111,109],"tags":[221,7,8],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v14.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to redirect all http to https in NGINX - CloudInsidr<\/title>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cloudinsidr.com\/content\/how-to-redirect-all-http-to-https-in-nginx\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to redirect all http to https in NGINX - CloudInsidr\" \/>\n<meta property=\"og:description\" content=\"When setting up https on an existing server, you need to provide a redirect for all those visitors arriving via http backlinks. Here is how to do this.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cloudinsidr.com\/content\/how-to-redirect-all-http-to-https-in-nginx\/\" \/>\n<meta property=\"og:site_name\" content=\"CloudInsidr\" \/>\n<meta property=\"article:published_time\" content=\"2018-09-06T11:15:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-09-06T11:18:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.cloudinsidr.com\/content\/wp-content\/uploads\/2018\/09\/work-731198-1024x683.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"683\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#website\",\"url\":\"https:\/\/www.cloudinsidr.com\/content\/\",\"name\":\"CloudInsidr\",\"description\":\"Cyber security, infotech\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.cloudinsidr.com\/content\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/how-to-redirect-all-http-to-https-in-nginx\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/www.cloudinsidr.com\/content\/wp-content\/uploads\/2018\/09\/work-731198.jpg\",\"width\":5472,\"height\":3648,\"caption\":\"fixing bugs\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/how-to-redirect-all-http-to-https-in-nginx\/#webpage\",\"url\":\"https:\/\/www.cloudinsidr.com\/content\/how-to-redirect-all-http-to-https-in-nginx\/\",\"name\":\"How to redirect all http to https in NGINX - CloudInsidr\",\"isPartOf\":{\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/how-to-redirect-all-http-to-https-in-nginx\/#primaryimage\"},\"datePublished\":\"2018-09-06T11:15:47+00:00\",\"dateModified\":\"2018-09-06T11:18:29+00:00\",\"author\":{\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#\/schema\/person\/dd6ee9cb21cf05763fd7cff3d6f11b2b\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.cloudinsidr.com\/content\/how-to-redirect-all-http-to-https-in-nginx\/\"]}]},{\"@type\":[\"Person\"],\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#\/schema\/person\/dd6ee9cb21cf05763fd7cff3d6f11b2b\",\"name\":\"Cloud Insidr\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.cloudinsidr.com\/content\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8b2fa1415b3d573b97d818b8f8f83b7c?s=96&d=mm&r=g\",\"caption\":\"Cloud Insidr\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/posts\/2363"}],"collection":[{"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/comments?post=2363"}],"version-history":[{"count":3,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/posts\/2363\/revisions"}],"predecessor-version":[{"id":2368,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/posts\/2363\/revisions\/2368"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/media\/2365"}],"wp:attachment":[{"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/media?parent=2363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/categories?post=2363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudinsidr.com\/content\/wp-json\/wp\/v2\/tags?post=2363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}