This is most effective method of redirecting web traffic to SSL in Nginx web server. According to Nginx documentation, they do not recommend to use ‘rewrite’ directive, instead advised to use ‘return’ directive. The guidelines regarding Nginx directive can be found at official Nginx document . So let’s look at how to redirect http to https Nginx .
1) Open Nginx config file of virtual host.
ex:- sudo vim /etc/nginx/sites-available/yourdomain.com
2) Insert following code snipet.
server { listen 80; server_name yourdomain.com; return 301 https://$server_name$request_uri; } server { listen 443 ssl; server_name yourdomain.com; #rest of the configuration code goes in here. }
Nginx ssl redirecting configuration is completed. comment here if you have any question at all.