How To Setup Nginx Reverse Proxy Server On Ubuntu 20.04

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, command ssh root@serverip

Import the repository’s package signing key

command wget to download nginx signing key

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

Add Repository

paste the line below into command line

deb [arch=amd64] 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:

then command apt install nginx to install nginx

Ensure NGINX is running and and enabled:

command systemctl enable nginx

Configure NGINX

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; location / { proxy_pass http://localhost:3030/; } }

in the line above replace 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; 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 :)



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Zack Sinder

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