- 3 NGINX Configuration and 4 Docker Setup must be done.
Assumptions
- Container ports are published in the compose files as
127.0.0.1:<HOST_PORT>:<CONTAINER_PORT>and opened to the outside only through NGINX. The settings in 4 Docker Setup also bind ports published without an IP address to127.0.0.1. - Commands are run on the server with root rights (
sudo).
Let’s put the containers we’ll install into a standard layout.
Let’s keep the Docker Compose files in one place:
sudo mkdir /opt/dockerPort Plan#
The containers open their ports only on 127.0.0.1, and NGINX forwards to these ports. To avoid clashes, the ports of the services installed in this series are:
| Service | Port | Note |
|---|---|---|
| 8 Vault Setup | 127.0.0.1:8200 | Not Docker, runs as a service on the host |
| 9 Vaultwarden Setup | 127.0.0.1:8004 | |
| 10 WordPress Setup | 127.0.0.1:8030–8049 | One port for each site |
| 11 Usememos Setup | 127.0.0.1:8001 | |
| 12 Syncthing Setup | 127.0.0.1:8384, 22000 | Not Docker, runs as a service on the host |
You can check the ports in use with sudo ss -tlnp | grep docker-proxy.
NGINX Settings#
WebSocket Support#
First let’s check whether the $connection_upgrade variable is already defined. If the same map is defined twice, NGINX gives an error.
sudo grep -rn connection_upgrade /etc/nginx/ # output should be emptyIf the output is empty, let’s create /etc/nginx/conf.d/websocket.conf like this:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}Proxy Template#
Let’s create /etc/nginx/templates/proxy.tmpl like this:
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;The basic configuration for a reverse proxy; we’ll use it in most of the virtual hosts that forward to containers.
proxy_set_header is inherited the same way as add_header: if even one proxy_set_header is defined in a location block, all the ones from the parent block stop working in that block. That’s why the safest way is to include the template in the same location block as proxy_pass.
compose.yaml file, with their ports, volumes, networks and settings written down in one place. docker compose up -d applies the file.server_name), so one server can host many domains.