missing environmental variables nginx container
See original GitHub issueHi, I am trying to evaluate cookiecutter-django, so far its a great tool to start a project. everything is going smooth except when I tried to use docker with certbot, i’m having this error.
nginx_1 | 2016/06/15 07:55:36 [emerg] 1#1: invalid port in upstream "___LETSENCRYPT_IP___:___LETSENCRYPT_PORT___" in /etc/nginx/nginx.conf:42
start.sh contains
sed -i "s/___LETSENCRYPT_IP___/$LETSENCRYPT_PORT_80_TCP_ADDR/g" /etc/nginx/nginx.conf
sed -i "s/___LETSENCRYPT_PORT___/$LETSENCRYPT_PORT_80_TCP_PORT/g" /etc/nginx/nginx.conf
I’m not a guru here, but I can see that the script is referencing with environmental variables, but when i tried to inspect the enviromental variables in nginx container, I didn’t see anything related to letsencrypt.
[root@localhost]# docker-compose run nginx bash
Starting tbpcsuite_certbot_1
Starting tbpcsuite_postgres_1
Starting tbpcsuite_redis_1
Starting tbpcsuite_django_1
root@b7d12c245b86:/# set
BASH=/bin/bash
BASHOPTS=checkwinsize:cmdhist:complete_fullquote:expand_aliases:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="4" [1]="3" [2]="30" [3]="1" [4]="release" [5]="x86_64-pc-linux-gnu")
BASH_VERSION='4.3.30(1)-release'
COLUMNS=197
DIRSTACK=()
EUID=0
GROUPS=()
HISTFILE=/root/.bash_history
HISTFILESIZE=500
HISTSIZE=500
HOME=/root
HOSTNAME=b7d12c245b86
HOSTTYPE=x86_64
IFS=$' \t\n'
LINES=73
MACHTYPE=x86_64-pc-linux-gnu
MAILCHECK=60
MY_DOMAIN_NAME=www.192.168.33.10.xip.io
NGINX_VERSION=1.11.1-1~jessie
OPTERR=1
OPTIND=1
OSTYPE=linux-gnu
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PIPESTATUS=([0]="1")
PPID=0
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
PS2='> '
PS4='+ '
PWD=/
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
SHLVL=1
TERM=xterm
UID=0
_=']'
I’m lost, any guidance I will appreciate.
Thanks,
Issue Analytics
- State:
- Created 7 years ago
- Comments:23 (20 by maintainers)
Top Results From Across the Web
How can I use environment variables in Nginx.conf
From the official Nginx docker file: Using environment variables in nginx configuration: Out-of-the-box, Nginx doesn't support using environment variables ...
Read more >Using environment variables in nginx configuration not working
From within the container I observe the following: $ ls /etc/nginx/templates/ foobar.conf.template # as expected $ ls /etc/nginx/ ...
Read more >Substitute environment variables in NGINX config from docker ...
Since nginx 1.19 you can now use environment variables in your configuration with docker-compose. I used the following setup:
Read more >Making environment variables accessible in front-end containers
This article shows you how to inject environment variables directly into your codebase as you build your container.
Read more >Nginx Docker and Environment Variables - ITNEXT
Variables are accessible in any other .conf files in Nginx. To use the variable just use ${VARIABLE_NAME} and that's it. To passing the ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Before we dig deeper into correcting this issue, I just wanted to compliment @mjsisley on the work he’s done on
Let's Encrypt
andCertbot
in Cookiecutter Django. He’s solving a very hard problem, which is ensuring easy-to-use HTTPS for all users done through the abstraction that occurs when generating Cookiecutter templates.With that, I also want to say that I expected a few bumps along the way, the same we encountered when we were polishing our Celery and Docker setups. These things happen, and it’s perfectly okay. Especially in a framework like Cookiecutter Django which likes to push certain boundaries.
To summarize: Thank you @mjsisley for your hard work on the Certbot stuff. 💃
@jamespacileo You can use the names of the containers instead of the env. vars (see #636 ) - docker’s new networking handles the name resolution.
The problem is nginx isn’t happy if one of the upstreams isn’t up. After we run with the initial nginx.conf and run certbot, we restart with the nginx-secure.conf but certbot is no longer up. Since nginx-secure.conf references certbot (and it needs to in order to have renewals work), nginx can’t switch to the new conf.
I’ve updated the original pull request (#636) with a better workaround that should support renewals. By setting the proxy_pass server as a variable and using the resolver directive, I’m telling nginx to perform the container name -> resolution dynamically. I’m getting the dns server of the container from /etc/resolv.conf (this will point at the docker network dns server) and setting the resolver to it.
Based on: https://trac.nginx.org/nginx/ticket/658 https://tenzer.dk/nginx-with-dynamic-upstreams/ http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass