How To Setup Nginx Reverse Proxy Server On Ubuntu 20.04

Zack Sinder
2 min readFeb 3, 2022

Hello in this tutorial am going to walk you through how to setup nginx reverse proxy server from scratch

When You Deploy Your Ubuntu 20.04 Droplet you will connect to it using ssh as root user,

Using The Command

`ssh root@serverip`

Import the repository’s package signing key

When you are at root level use

command wget http://nginx.org/keys/nginx_signing.key to download nginx signing key

then command apt-key add nginx_signing.key to install the key

Add Repository

command nano /etc/apt/sources.list.d/nginx.list

paste the line below into command line

deb [arch=amd64] http://nginx.org/packages/mainline/ubuntu/ focal nginx

the word focal inside the line above is the codename of ubuntu 20.04 release if you are using different distribution make sure you change the focal word to your server codename.

Install NGINX:

command apt update to update packages

then command apt install nginx to install nginx

Ensure NGINX is running and and enabled:

command systemctl start nginx

command systemctl enable nginx

Configure NGINX

Now we are going to configure our nginx reverse proxy server

now use the command below to create conf file in your nginx server and change the node to any name you want

command nano /etc/nginx/conf.d/node.conf

then paste the code below inside there

server { listen 80; listen [::]:80; server_name example.com; location / { proxy_pass http://localhost:3030/; } }

in the line above replace example.com with your actual domain name and proxy_pass http://localhost:3030 with the port you want to pass traffic to.

another use case is passing traffic to external server and using this server to point your domain to which will hide your original hosting ip address

for example if you want to proxy remote server which is not in you localhost replace the code above with this line below

server { listen 80; listen [::]:80; server_name example.com; location / { proxy_pass http://remote_server_ip:80; proxy_set_header HOST $host; } }

when you are finished editing the file save with ctrl + 0 and then enter then exit with ctrl+x

then use the command mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.disabled

to disable your default conf file and then command nginx -t to test it if there are no errors then continue with

command nginx -s reload to reload the server

then go to your domain dns and point it to this server address and it should work fine

some errors to consider are sometime ssl issues but will cover how to install it in another article.

Thats all, to be honest this article was for me to use it again if i forget easily without research again. I am a beginners as you can tell from my writing and also for anyone who faces this issue in the future. Have a Nice day Bye :)

--

--

Zack Sinder

Just sharing what am going through and findings in the tech and cloud industry