Forcing your Nginx site to load securely

Overview

After you have added an SSL certificate to your domain, DreamHost automatically redirects the URL visitors use to view your site from HTTP to HTTPS. The 'S' ensures that your connection is encrypted. For example:

  • https://example.com

There's nothing on your end you must do in order to force your site to use the secure URL. However, in some special cases, it may be necessary for you to create your own custom configuration file to force the redirect from HTTP to HTTPS.

Adding custom code is only necessary if your website requires specific code to force the redirect. If so, you will need to first disable the automatic redirect in your panel.

Once disabled, you can then proceed with adding your custom redirect file.

Redirecting non-secure traffic to HTTPS

To redirect a URL in a website running on an Nginx server, you must manually create a redirects.conf file. You will then add your redirect code to this file. View the following article for instructions on how to locate your Nginx configuration file location.

Once located, you can edit or create this file using an FTP client or SSH.

This redirect forces your site to load the HTTPS version of your site to ensure your visitor's connections are encrypted. Add the following code to your redirects.conf file.

if ($server_port = 80) {
  rewrite ^/(.*)$ https://example.com/$1 permanent;
}

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?