If your website is hosted with NGINX and it has SSL enabled, it’s best practice to disable HTTP completely and force all incoming traffic over to the HTTPS version of the website. This guide will show you how to configure a 301 redirect HTTP to HTTPS to avoid duplicate content and ensure that all of the site’s users are only browsing the secure version of your website. In this guide, we’ll assume you’re already using NGINX on a Linux system and want to implement an nginx redirect HTTP to HTTPS. Even if a user happens to follow an http:// link, the site should send them to the correct and secured page, which happens instantly and without the user’s intervention.
There are two ways to setup this redirection in NGINX. One method allows you to configure the redirection for individual sites. The other method can redirect HTTP to HTTPS for all NGINX sites on your server, which is handy if you have multiple sites setup and want to avoid having to apply the exact same redirection to each one. We’ll cover the step by step instructions for both methods below. Let’s get started.
Using Apache instead of NGINX? We’ve written a separate guide for how to use Apache to redirect all HTTP traffic to HTTPS.
In this tutorial you will learn:
- How to redirect HTTP to HTTPS for individual NGINX websites
- How to redirect HTTP to HTTPS for all NGINX websites