Reverse Proxy Server is type of server which act as middleman between client and server. When client request to server, reverse proxy receive the request then forward to the server. Then, server send the response back to reverse proxy and the reverse proxy forward back to client.

Prerequisite

  1. VM, im using ubuntu 22.04
  2. sudo access

Install nginx

First, we need to install nginx as reverse proxy.

sudo apt update -y && sudo apt install nginx -y

Install Docker

Then, we can install docker engine using single command line,

bash <(curl -s https://raw.githubusercontent.com/man20820/docker-autoinstaller/main/run.sh)

Or you can install manually, check the step on docker documentation.

Run your docker container

In this example, im using nodejs hello world for the container

source: https://github.com/man20820/nodejs-hello-world/blob/dev/index.js

i already run the docker container and exposed in port 3000

Pointing domain to the server

pointing your domain with A record to server’s ip address

Configure NGINX

create virtualhost in /etc/nginx/sites-available

create link from sites available to sites enabled

ln -s /etc/nginx/sites-available/reverse-proxy.tkjpedia.com /etc/nginx/sites-enabled/reverse-proxy.tkjpedia.com

check nginx configuration

nginx -t

reload the nginx service

service nginx reload

Testing reverse proxy

Working!

Setup letsencrypt SSL with certbot

to use ssl, we can setup with certbot. we need to install certbot and nginx plugin first.

sudo apt install certbot python3-certbot-nginx

setting certbot and select your host / domain

Test SSL / TLS with browser

Congratulation!