• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

Nginx Redirect HTTP to HTTPS

Written by Rahul, Updated on December 4, 2019

Nginx is an open-source, high-performance HTTP and reverse proxy server. This has become popular among many hosting providers. Everyone knows that transferring private data like credentials, payment information over insecure protocol is not secure. They can easily be sniffed by a MITM attacker. This tutorial will help you redirect incoming HTTP traffic to HTTPS in the Nginx web server.

Redirect ALL to HTTPS

This will redirect all requests hits to port 80 except domains with separate server blocks. To do this edit virtual host configuration file for your domain and add “return 301 https://$host$request_uri” statement under server section. This will redirect all the incoming requests on HTTP to corresponding https URLs.

server {
	listen 80 default_server;
	listen [::]:80 default_server;
	server_name _;
	
	return 301 https://$host$request_uri;
}

Redirect Specific Domain

You may want to redirect a specific domain to HTTPS. Use the following configuration on Nginx to redirect all HTTP requests on tecadmin.net to HTTPS.

server {
	listen 80 default_server;
	listen [::]:80 default_server;
	server_name tecadmin.net;
	
	return 301 https://$host$request_uri;
}

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
  • How To Install NVM on macOS with Homebrew 0
  • (Solved) apt-add-repository command not found – Ubuntu & Debian 0
  • How to Install .NET Core on Debian 10 0
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy