How to rewrite all HTTP requests into HTTPS in NGINX

I wanted to redirect all http requests to https requests on one of my last projects.

I just added following strokes into my NGINX configuration file

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

server {  
       listen         443 ssl;
       server_name    my.domain.com;
}

Tural Aliyev

I'm traveloholic, musicphile, technoholic, cinephile, workaholic software developer

Istanbul http://tural.us

Subscribe to Tural's Notebook

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!