That takes care of the communication barrier. We’re ready to set up NginX and configure it.
One config to bring them all — and in the droplet bind them
Configuration will have two parts. Initial configuration is part of the NginX container setup itself. Second will be the custom configuration of NginX.
NginX container
Our NginX container will be spun -up using docker-compose. You can use an alpine based NginX image. But we need more things from NginX, that is, we need SSL for each and every sub container and we want the SSL auto-renewed without administration. It takes more steps to install the necessary packages and scripts to get CERTBOT working on alpine. For the sake of convenience I will use nginx:stable image. But if you have resource constraints on your droplet, I advise using alpine and figure out the CERTBOT and CRON steps manually (at least for the first time).
For the NginX container, we will have a docker-compose.yml file, a Dockerfile inside a directory called ‘nginx’ and then another directory structure within that for nginx configuration.
The directory structure to setup the NginX container must be like so:
nginx/
├─ Dockerfile
├─ config/
│ ├─ conf.d/
│ │ ├─ prod/
│ │ │ ├─ example.conf
docker-compose.yml
- Note that the directory (./nginx/config/conf.d/prod ) is for the purpose of storing our configuration file for NginX. This will be bound to a volume so we can change the configuration on the fly later on. Easy for maintenance. Feel free to play around with it. Other files/directories are necessary.
note lines marked with ##Change this
The Dockerfile will look like so: