How to Redirect all http traffic to https in NGINX for a specific URL?

How to Redirect all http traffic to https in NGINX for a specific URL?

Nginx is reverse proxy, web server, load balancer.  When you have requirement to redirect all the traffic from one URL to redirect to another URL. 

Please add following section in the respective config file /etc/nginx/conf.d/example.conf. Change your server_name accordingly.

server {
       listen         80;
       server_name    example.com;
       return         301 https://$server_name$request_uri;
}

Then restart the nginx service.

service nginx restart

Now check the service status and redirection.

service nginx status

0 Comments