A reverse proxy is a bridge between the host (client) and the application server. It routes client requests, relaying data to target servers, then delivers the server’s response to the client. In this tutorial, I’ll show how to set up the Nginx reverse proxy for your apps and domains.
We only use Ubuntu servers at Honeyside. We recommend you to do the same. Therefore, this guide will only cover installation and configuration on Ubuntu.
First, let’s install Nginx using the apt
command:
sudo apt update sudo apt install nginx
There are two Nginx folders you should really care about:
/etc/nginx/sites-available
should contain one configuration file for each domain./etc/nginx/sites-enabled
should contain one link to a file in sites-available per each active domain.Let’s disable the default virtual host, by removing the link in sites-enabled. The configuration file will still be in sites-available for future reference, but the configuration will not be loaded anymore.
sudo unlink /etc/nginx/sites-enabled/default
Let’s say you want to create a reverse proxy for your example.com domain. You will now create an example.conf file under /etc/nginx/sites-available
.
cd /etc/nginx/sites-available/ nano example.conf
Paste in the following configuration:
server { listen 80; server_name example.com; location / { proxy_pass http://localhost:4000; } }
This will reverse proxy your requests to port 4000, where you are running an app or service (such as one of our CodeCanyon items).
You need to create a symlink to the configuration under /etc/nginx/sites-enabled
.
Run the following command:
sudo ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/example.conf
Don’t know what a symlink is? Basically, you now have one configuration file (under sites-available) and one “link” to that file (under sites-enabled). Should you need to edit the configuration in the future, any changes applied to /etc/nginx/sites-available/example.conf will be automatically applied to /etc/nginx/sites-enabled/example.conf.
You can now test the Nginx configuration, then apply it by restarting the service:
service nginx configtest service nginx restart
That’s it, congratulations on installing Nginx on your Ubuntu machine!
You should now be able to access the application running on port 4000 by navigating to http://example.com (replace with your domain name).
If you wish to add SSL / HTTPS to your Nginx installation, check out our tutorial here: Nginx reverse proxy - securing with Let’s Encrypt SSL.
Quick Links
Legal Stuff