Redirect HTTP Requests To HTTPS On Nginx

Posted on


This writeup shows you how to setup Nginx to redirect non-secure (http) requests to secure (https) ones.


  • You have a Vultr Linux instance running Nginx.
  • Your have domain name (e.g whose DNS A records for “@” and “www” are pointing to the IP of your Vultr machine above.
  • Ideally you should also have SSL setup on your instance.

Setup redirect

Add an additional server block to your vhost setting so it looks similar to below:

server {
    listen 80;
    return 301$request_uri;

server {
    listen 443 ssl;

    ssl_certificate     /path/to/cert-crt.crt;
    ssl_certificate_key /path/to/cert-key.key;
    #other site settings go here (e.g. ssl, logs, site root)

Written by Lami Adabonyan

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article

Leave a Reply

Your email address will not be published. Required fields are marked *