Configure Nginx redirect HTTP to HTTPS

We now need to use the security protocol SSL for Web sites are fairly common because Google has increased the weight ranking for this site. After installing SSL success, how to redirect all external links from HTTP to HTTPS with Nginx, refer to this article.

Edit the configuration file of nginx (nginx. conf) or if you use the vpssim then you modify the configuration file for each domain in the folder/etc/nginx/conf.d/

Add or adjust the following redirect structure:

rewrite ^ https://$server _ name $ request_uri? Permanent;

Finally you will file with content similar to this:

Server {
server_name www.example.com;
rewrite ^ https://$server _ name $ request_uri? Permanent;
}

Restart Nginx

Service nginx restart