{"id":3548,"date":"2018-08-08T02:58:53","date_gmt":"2018-08-08T02:58:53","guid":{"rendered":"https:\/\/pariswells.com\/blog\/?p=3548"},"modified":"2018-08-08T02:59:01","modified_gmt":"2018-08-08T02:59:01","slug":"enable-nginx-webserver-for-hsts-and-www-redirect","status":"publish","type":"post","link":"https:\/\/pariswells.com\/blog\/research\/enable-nginx-webserver-for-hsts-and-www-redirect","title":{"rendered":"Enable NGinx Webserver for HSTS and www redirect"},"content":{"rendered":"\n<p>You need to be listing on port 80 then redirect to https:\/\/ 443 , then after you can redirect non to www ( or the other way around ) for SEO<\/p>\n\n\n\n<p>Default nginx.conf location is in \/etc\/nginx\/<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n#Listen on http first and redirect to https:\/\/\nlisten 80 default_server;\nlisten [::]:80 default_server;\nserver_name www.domain.com domain.com;\nreturn 301 https:\/\/domain.com$request_uri;\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n#Listen on HTTPS:\/\/ then redirect non www to www\nlisten 443 ssl;\nserver_name www.domain.com;\nssl_certificate \/etc\/pki\/nginx\/star2018.pem;\nssl_certificate_key \/etc\/pki\/nginx\/wildcard.key;\nroot \/usr\/share\/nginx\/html;\nadd_header Strict-Transport-Security \"max-age=31536000; includeSubDomains; preload\";\n# Set client body size to 10M.\nclient_max_body_size 10M;\nif ($host = 'domain.com') {return 301 https:\/\/www.domain.com$request_uri;}\n# Load configuration files for the default server block.\ninclude \/etc\/nginx\/default.d\/*.conf;\n\nlocation \/ {\n        index index.php;\n        try_files $uri \/index.php$is_args$args;\n\n}\n\nerror_page 404 \/404.html;\n    location = \/40x.html {\n}\n\nerror_page 500 502 503 504 \/50x.html;\n    location = \/50x.html {\n}\nlocation ~ \\.php$ {\n\n        fastcgi_pass unix:\/var\/run\/php-fpm\/php-fpm.sock;\n\n         fastcgi_index index.php;\n         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n         include fastcgi_params;\n\n\n }<\/code><\/pre>\n\n\n\n<p>After saving this you need to restart nginx<\/p>\n\n\n\n<p>sudo service nginx restart<\/p>\n\n\n\n<p>Then use :\u00a0<a href=\"https:\/\/hstspreload.org\">https:\/\/hstspreload.org<\/a> to test<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You need to be listing on port 80 then redirect to https:\/\/ 443 , then after you can redirect non to www ( or the other way [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2506,1526,2611],"class_list":["post-3548","post","type-post","status-publish","format-standard","hentry","category-research","tag-nginx","tag-redirect","tag-www"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/3548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/comments?post=3548"}],"version-history":[{"count":1,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/3548\/revisions"}],"predecessor-version":[{"id":3550,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/3548\/revisions\/3550"}],"wp:attachment":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/media?parent=3548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/categories?post=3548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/tags?post=3548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}