HomeTeamProductsForumSupport

Nginx reverse proxy setup on Ubuntu servers

By Daniele Molinari
Published in Tutorials
January 21, 2023
1 min read
Nginx reverse proxy setup on Ubuntu servers

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.

Install Nginx

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.

Disable default settings

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

Configure reverse proxy

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).

Enable reverse proxy

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.

Restart Nginx

You can now test the Nginx configuration, then apply it by restarting the service:

service nginx configtest
service nginx restart

Conclusions

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).

Next steps

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.


Tags

#nginx#reverse-proxy#ubuntu#how-to
Previous Article
Saint Valentine Promo 2023
Daniele Molinari

Daniele Molinari

Lead Software Engineer

Table Of Contents

1
Install Nginx
2
Disable default settings
3
Configure reverse proxy
4
Enable reverse proxy
5
Restart Nginx
6
Conclusions
7
Next steps

Related Posts

Securing Nginx reverse proxy with Let's Encrypt SSL
January 07, 2024
1 min

Quick Links

Our ProductsOur TeamSupport

Social Media

VAT ID IT08510780722 - REA BA-631501 - PEC honeyside@pec.it