This is a simple configuration that uses docker images nginxproxy/nginx-proxy
& nginxproxy/acme-companion
to easily create SSL-enabled websites on any server.
nginx-proxy
is an image that automatically sets up a proxy based on nginx. It watches new containers creation / start and, if the container has a VIRTUAL_HOST
environment var, will automatically create the configuration for it (no more site-enabled site-available hassle). If there is only one port exposed on the container, nginx-proxy
will automatically proxy to that port.
It's highly configurable (globally, per virtual host, per location, per...)
acme-companion
will automatically generate the SSL certificates using let's encrypt
if the container has a LETSENCRYPT_HOST
env var.
First, install docker if not already done
What I usually do (using the web user but you can change for your own or just change the directory):
mkdir /home/web/www
mkdir /home/web/www/conf
mkdir /home/web/www/conf/conf.d
mkdir /home/web/www/conf/vhost.d
mkdir /home/web/www/conf/htpasswd
mkdir /home/web/www/websites
touch /home/web/www/docker-compose.yml
then I save the content of docker-compose-proxy.yml in it
I create the nginx-proxy
network that allows the nginx-proxy
container to find the containers it needs to connect to the web
docker network create nginx-proxy
then I start the proxy
cd /home/web/www/
docker compose up -d
Whenever I need to add a website (for this example myWesbite.xyz
):
mkdir /home/web/www/websites/myWesbite.xyz
mkdir /home/web/www/websites/myWesbite.xyz/public
touch /home/web/www/websites/myWesbite.xyz/docker-compose.yml
Content of docker-compose.yml
varies depending on your need.
- node (docker-compose-node.yml)
- nginx (docker-compose-static.yml)
- node, postgres, adminer (docker-compose-node-postgres-adminer.yml)
- nginx, node, postgres (docker-compose-nginx-node-postgres.yml)
Whenever the content is set:
cd /home/web/www/websites/myWesbite.xyz
docker compose up -d