When running multiples web containers on a same machine, you must set a reverse proxy. This project aims to configure a simple nginx proxy.
- Copy
env.example
file to.env
and customize it if you want. - Copy
docker-compose.example.yml
file todocker-compose.yml
and customize it if you want. - Run
./proxy_ctl.sh up
Auto-signed certificate will be created inside volumes/certs
but if you want to use
your custom certificate, create the following files:
volumes/certs/default.crt
and volumes/certs/default.key
Be sure to protect correctly these files with good permissions.
Add nginx config files inside volumes/nginx/conf
.
In your docker-compose.yml
files, disable exposing ports 80 & 443 and append:
services:
my-web-service:
...
networks:
- proxy
...
networks:
proxy:
external: true
Note: If you changed PROXY_NETWORK
in the env file, change proxy
by this value.
Append to your command:
docker run ... --network proxy ...
Note: If you changed PROXY_NETWORK
in the env file, change proxy
by this value.
In case there is an error in one of your config files (e.g. container unreachable):
You have to run ./proxy_ctl.sh reload
to reload config. If it fails, it will not reload (safe in production environment).
At the first run or if the proxy container must restart, it will rename your bad config files with .disabled
suffix.
You will have to fix the config file (or maybe it's because a container is not reachable), then reload config with --force
option to re-enable it.
When proxy container restarts, if there are .disabled
files, it will test them and if config is fixed, it will automatically rename and enable them.
By default, if nothing is found, nginx will return the 503 error code (site in maintenance).
You can create your own maintenance page in volumes/nginx/html/maintenance/index.html
Run proxy_ctl upgrade
to upgrade proxy.
If you don't have git on the host, you can also manually copy the sources, then run proxy_ctl build
and proxy_ctl up
.
This project is licensed under the MIT License. See LICENSE.md for the full license text.
Author: Jean Prunneaux https://jean.prunneaux.com