Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Web Servers»Nginx»Nginx Redirect HTTP to HTTPS

    Nginx Redirect HTTP to HTTPS

    By RahulDecember 4, 20191 Min Read

    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.

    Advertisement

    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;
    }
    

    http https nginx virtualhost
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Configuring Nginx for Laravel on Ubuntu & Debian

    Configuring Nginx to Handle 100 Thousands Request Per Minute

    Configuring Nginx to Handle 100 Thousands Request Per Minute

    How To Set Up Nginx Reverse Proxy: A Step-By-Step Tutorial

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Configure Postfix to Use Gmail SMTP on Ubuntu & Debian
    • PHP Arrays: A Beginner’s Guide
    • Deploying Flask Application on Ubuntu (Apache+WSGI)
    • OpenSSL: Working with SSL Certificates, Private Keys and CSRs
    • How to Create and Read List in Python
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.