Reverse Proxy Nginx Docker Template

Short description on how to set up a reverse proxy using docker

Posted on June 4, 2021

I was looking for a simple and short tutorial on how to set up a reverse proxy using docker that I could use as a basis for other topics. Since the internet has nothing that satisfied me, I decided to write my own stuff in hope that others can benefit from it.

So this is the result. The accompanying repo can be found here.

The reverse proxy used here is structured as following:

  • Docker as a container
  • Nginx as server reachable from outside
  • Python3 simple HTTP Server as a server used inside

The repo contains the following files:

├── conf
│   └── default.conf (nginx configuration)
├── Dockerfile 
└── scripts
    └── (is starting everything when docker is started)

To run it do:

sudo docker build -t simple-reverse-proxy . && sudo docker run -ti -p simple-reverse-proxy

After that, the internal server can be reached from your host using the reverse proxy at

The content goes this way: (internal server inside docker) -> (proxy server inside docker) -> (final server listening on host)

The server listens on your host at because of the port forwarding


used in the docker command.

The web root is set in the Dockerfile

grep mkdir Dockerfile 
RUN mkdir -p /var/www/html

For the internal server I took the simple http server that python gives you.

python3 -m http.server
grep python3 scripts/
python3 -m http.server

but this could be any other web server as well.

Python’s server uses the folder where it is started, so the docker working directory is set to the web root and when you run the container the server will be invoked in /var/www/html:

grep WORKDIR Dockerfile                  
WORKDIR /var/www/html

If you want to use another web server assure yourself that it delivers its content from here or change it in the Dockerfile.

The connection between internal and proxy server is done inside the nginx config file default.conf:

cat conf/default.conf
server {
 listen 80;
 location / {

Python’s server module defaults to port 8000.

You can change these configurations points depending on what internal root server you want to use.