eugene-khyst / letsencrypt-docker-compose

Set up Nginx and Let’s Encrypt in less than 3 minutes with a Docker Compose project that automatically obtains and renews free Let's Encrypt SSL/TLS certificates and sets up HTTPS in Nginx for multiple domain names. Configuration is done using a simple CLI tool.
Apache License 2.0
473 stars 218 forks source link

[emerg] 1#1: host not found in upstream #47

Closed navanjr closed 1 year ago

navanjr commented 1 year ago

Thanks for this project!

in my case nginx won't start if an upstream container is not running.

I am attempting to use the nginx resolver directive to allow nginx to run if my upstream container is down.

Where would be the appropriate place to apply this nginx directive?

I have tried in my vhosts files...

location / {
    resolver 127.0.0.11 valid=30s ipv6=off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_pass http://my_docker_container:3000/;
}

and in site.conf.tpl...

resolver 127.0.0.11 valid=30s ipv6=off;

server {
    listen 80;
    server_name ${domain} www.${domain};

    location /.well-known/acme-challenge/ {
        root /var/www/certbot/${domain};
    }

    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl;
    server_name ${domain} www.${domain};

    ssl_certificate /etc/nginx/sites/ssl/dummy/${domain}/fullchain.pem;
    ssl_certificate_key /etc/nginx/sites/ssl/dummy/${domain}/privkey.pem;

    include /etc/nginx/includes/options-ssl-nginx.conf;

    ssl_dhparam /etc/nginx/sites/ssl/ssl-dhparams.pem;

    include /etc/nginx/includes/hsts.conf;

    include /etc/nginx/vhosts/${domain}.conf;
}

Neither have worked.

eugene-khyst commented 1 year ago

Version 2 has been recently released. Docker DNS resolver is supported out of the box. https://github.com/evgeniy-khist/letsencrypt-docker-compose#initial-setup

Or update your config to have Nginx variable. Together with resolver it's required to let Nginx start if an upstream server is unreachable. https://github.com/evgeniy-khist/letsencrypt-docker-compose/blob/1fd9edba4e52432b6fd674a553aaae2e8ba9c363/templates/servers.conf.hbs#L41