Nginx reverse proxy to multiple docker apps

Updated: 11 August 2024

I often create and edit Customer demo apps, with Docker. I’ve found it very useful to serve all of these apps behind one Nginx reverse proxy webserver. The notes below show how I achieve this with the Digital Ocean Nginx config tool and deployment of the config with git.

Getting started

  1. Create a Digital Ocean LEMP Droplet.
  2. Install Docker on the LEMP Droplet.
  3. Install and run your Docker applications, binding each to a different host port.

Domains

Each demo needs a URL which can be given to the Customer. I tend to use subdomains of my business domain e.g. http://a-demo.christaylordeveloper.co.uk. For each subdomain I configure an A-record, pointing at the IP address of the LEMP server.

NGINXConfig

  1. Create nginx config for your site(s) with this Digital Ocean tool https://www.digitalocean.com/community/tools/nginx
  2. On the Reverse proxy tab, insert into the proxy_pass field the port numbers you set earlier when running-up your docker apps.
  3. Download your Nginx config.

Git

  1. Make a local git repo of the downloaded config and push to a remote.
  2. Add to your repo a .gitignore file which will ignore everything else in the LEMP droplet /etc/nginx directory.
  3. Clone the git repo into the LEMP server /etc/nginx/ directory
  4. Restart the Nginx service.

Edits

At some point you will need to add, edit or remove the Docker applications:

  1. Load the URL in file nginxconf.txt. This restores your configuration into the Digital Ocean tool.
  2. Make the required edits and download again.
  3. Commit the changes into your local git repo and push to remote.
  4. Pull changes into your LEMP server.

Leave a comment