Force SSL Redirection on Nginx Server – HTTP to HTTPS

Force SSL Redirection on Nginx

In today tutorial we are going see about Force SSL Redirection on Nginx Web Server.

Redirect all HTTP Traffic to HTTPS –  For Apache, we write the Force SSL redirect Rule on HTACCESS File but on Nginx, it’s slightly different we need to write a rule on our sites Nginx configuration file.

Nginx Rewrite Guide: Creating NGINX Rewrite Rules

Permanent 301 HTTPS SSL redirection is Very Important on SEO and Ranking Part

Here is the Steps & Solutions to Force SSL Redirection on Nginx Server

How to Force Redirect the HTTP to HTTPS on Nginx?

  • Open your website Nginx Conf File (Note: don’t add this code on nginx.conf file)
  • if you install it via LEMP you can find your website conf file /etc/nginx/sites-available/default or Install it via Manual Method nano /etc/nginx/conf.d/example.conf
  • After opening your Config File add this Below SSL redirection code on server Block
# Redirect HTTP to HTTPS
 if ($scheme = http) {
 return 301 https://$server_name$request_uri;

Force SSL Redirection on Nginx


  • if the above Method not working then try this Below Method
return 301 https://$server_name$request_uri;

Force SSL Redirection on Nginx


server { 
 listen 80;
 listen [::]:80;

# Redirect HTTP to HTTPS
 return 301 https://$server_name$request_uri;

  • After adding the Rules Save the File
  • Restart the Nginx server
sudo service nginx restart
  • After restarting the Nginx Web server Open your website/blog on browser with HTTP URL It will Redirect to HTTPS
  • That’s all Successfully we configure the Force HTTPS Redirection on Nginx Server

Example Nginx Configuration for Both SSL and HTTP/2

From the Editor’s Desk

Hope the above Method will Help you to Redirect the HTTP Traffic into HTTPS if you are facing any issue or need any help on configuration Just drop your comments here I will Guide you 🙂



Was this article helpful?

Your feedback helps us improve