Nginx, redirect www and force HTTPS

If you would like to redirect all non-https to https due that Google likes it this way, and of course make it your site more secured, you can easily make it so using Nginx. Due to the great power or Nginx which runs in millions of website, its small footprint and because is free make it a good choice for any website.

I am gonna post some snippets of my configuration that has worked very well and it’s supposed to be the recommended way..

###### redirect any http https with proper redirect code #######################
server {
    	listen       80;
        server_name yourSite.com www.yourSite.com.com;
    	return 301 https://www.yourSite.com.com$request_uri;
    
    }

Now you properly have your website redirect correctly to your https site without much code change, apply the changes make sure you check your configuration. Using Nginx command to check its properly formatted.

sudo nginx -t

After checking configuration then you reload Nginx

sudo nginx reload

That’s it, remember I am just a Tech User just like you.