nginx-certbot icon indicating copy to clipboard operation
nginx-certbot copied to clipboard

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

Open igi-1w3r53n opened this issue 4 years ago • 2 comments

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.

igi-1w3r53n avatar Dec 01 '20 17:12 igi-1w3r53n

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

toastyrye avatar Dec 09 '20 18:12 toastyrye

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;\"'"

c-mart avatar Mar 14 '23 22:03 c-mart