wmnnd / nginx-certbot

Boilerplate configuration for nginx and certbot with docker-compose
MIT License
3.16k stars 1.17k forks source link

Using environment variables in nginx configuration not working because of renew certificates command #100

Open igi-1w3r53n opened 3 years ago

igi-1w3r53n commented 3 years ago

Related: https://github.com/nginxinc/docker-nginx/issues/422#issuecomment-644299743

I am using env variables in my docker-compose file and i was not able to get this setup running. It seems that nginx ignores its default commands and template compilation when the "command: "/bin/sh -c 'while :; do sleep 6h ..." renew certificates command is set in docker-compose file.

Maybe someone has a similar issue.

toastyrye commented 3 years ago

envsubst can be used to support environmental variables. see here: https://serverfault.com/questions/577370/how-can-i-use-environment-variables-in-nginx-conf

this could also be a feature to add to the repo

c-mart commented 1 year ago

Yes, the ENTRYPOINT script (invoked here) appears responsible for this behavior. If the first argument to the container's CMD (as defined in command: in docker-compose.yml) is not nginx or nginx-debug, then the entrypoint script never looks for the 20-envsubst-on-templates.sh script. That is the case with the docker-compose.yml in this repo, because the command: starts with a while loop to reload Nginx every 6 hours.

I got it working by modifying the command: to run the envsubst script before starting Nginx:

command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & /docker-entrypoint.d/20-envsubst-on-templates.sh; nginx-debug -g \"daemon off;\"'"