diff --git a/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile b/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile index b9e7985f..7ab10d4d 100644 --- a/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile +++ b/{{cookiecutter.project_slug}}/compose/nginx/Dockerfile @@ -5,4 +5,5 @@ ADD nginx.conf /etc/nginx/nginx.conf ADD start.sh /start.sh ADD nginx-secure.conf /etc/nginx/nginx-secure.conf ADD dhparams.pem /etc/ssl/private/dhparams.pem +CMD /start.sh {% endif %} diff --git a/{{cookiecutter.project_slug}}/compose/nginx/nginx-secure.conf b/{{cookiecutter.project_slug}}/compose/nginx/nginx-secure.conf index c014c282..cd0fe9a3 100755 --- a/{{cookiecutter.project_slug}}/compose/nginx/nginx-secure.conf +++ b/{{cookiecutter.project_slug}}/compose/nginx/nginx-secure.conf @@ -37,10 +37,12 @@ http { server_name ___my.example.com___ www.___my.example.com___; location /.well-known/acme-challenge { - proxy_pass http://certbot:80; + # Since the certbot container isn't up constantly, need to resolve ip dynamically using docker's dns + resolver ___NAMESERVER___; + set $certbot_addr_port certbot:80; + proxy_pass http://$certbot_addr_port; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Forwarded-Proto $scheme; } @@ -66,7 +68,9 @@ http { ssl_dhparam /etc/ssl/private/dhparams.pem; location /.well-known/acme-challenge { - proxy_pass http://certbot:443; + resolver ___NAMESERVER___; + set $certbot_addr_port certbot:443; + proxy_pass http://$certbot_addr_port; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto https; diff --git a/{{cookiecutter.project_slug}}/compose/nginx/start.sh b/{{cookiecutter.project_slug}}/compose/nginx/start.sh index 2b358ee7..fa40ed9a 100755 --- a/{{cookiecutter.project_slug}}/compose/nginx/start.sh +++ b/{{cookiecutter.project_slug}}/compose/nginx/start.sh @@ -49,8 +49,14 @@ echo replacing ___my.example.com___/$MY_DOMAIN_NAME # Put your domain name into the nginx reverse proxy config. sed -i "s/___my.example.com___/$MY_DOMAIN_NAME/g" /etc/nginx/nginx-secure.conf +# Add the system's nameserver (the docker network dns) so we can resolve container names in nginx +NAMESERVER=`cat /etc/resolv.conf | grep "nameserver" | awk '{print $2}' | tr '\n' ' '` +echo replacing ___NAMESERVER___/$NAMESERVER +sed -i "s/___NAMESERVER___/$NAMESERVER/g" /etc/nginx/nginx-secure.conf + + #go! -kill $(ps aux | grep 'nginx' | awk '{print $2}') +kill $(ps aux | grep 'nginx' | grep -v 'grep' | awk '{print $2}') cp /etc/nginx/nginx-secure.conf /etc/nginx/nginx.conf nginx -g 'daemon off;'