Search The Hostwinds Guides Knowledge Base

Nginx Reverse Proxy with SSL

Share This Article

Nginx is a powerful tool. It allows you to serve multiple apps, websites, load-balanced applications and much more. This flexibility is all powered by a relatively simple configuration system that uses nearly-human-readable configuration files. This guide will demonstrate how to utilize set up an Nginx Reverse Proxy with SSL on a Hostwinds Cloud VPS.

Prerequisites

This guide will assume a general understanding of using a Linux-based system via command line, and will further assume the following prerequisites:

  • Ubuntu 18.04
  • Non-root user
  • App Running on Desired Reverse-Proxy Port (This guide will assume port 3000)
  • DNS A Name Record for Domain Desired
  • SSL Certificate for the Domain

Nginx Configuration

The Nginx-full package defaults to a dynamic Shared Virtual Host environment. The configuration files for each Virtual Host are available for use here:

This location will have a file called default available to use as a base template. However, in this guide, we will manually create a new configuration file and populate it as needed. Once logged in as your non-root user, issue this command to start the process:

Be sure to replace domain.tld with the domain you are actually using.

Next, we move to modify that file to make it perform the tasks we need it to do. We will be using vim in this guide as the text editor. You may use nano or any other text editor based on your personal preference.

Now that the file exists, add the following text to this file. Modify the text where indicated to reference your domain, the port your app is using, and your SSL certificate paths. This file will be the main configuration for the reverse proxy:

Save the file and exit the text editor.

Test the Nginx Configuration

Now that the configuration is created, we have to tell Nginx to check for the file on load. We will make a symbolic link:

Next, we test the configuration before restarting the Nginx system service

Afterward, It should run the test and output the following message upon a success:

We now know that the configuration file will not cause a crash, so let’s restart the Nginx service and test the app.

You should now have access to the app that is running on the defined port by browsing to domain.tld as depicted in the Nginx configuration file created earlier.

Related Articles