Docker-letsencrypt-nginx-proxy-companion: Nginx exited after restart

Created on 8 Jun 2016  路  7Comments  路  Source: nginx-proxy/docker-letsencrypt-nginx-proxy-companion

Hi,

after first start everything is ok, but after restart containers exited with error:
nginx: [emerg] open() "/etc/nginx/vhost.d/default" failed (2: No such file or directory) in /etc/nginx/conf.d/default.conf:41.
I used docker-compose.yml from examples for v1: https://github.com/fatk/docker-letsencrypt-nginx-proxy-companion-examples/blob/master/docker-compose/v1/simple-site/docker-compose.yml

Could you tell me what is wrong?

Thanks

Enhancement

Most helpful comment

The first time the nginx container starts, /etc/nginx/conf.d/default.conf contains default configuration from the nginx image, and starts up successfully.

/etc/nginx/vhost.d/default is later created by letsencrypt-nginx-proxy-companion, and if that file exists while docker-gen parses the template to regenerate /etc/nginx/conf.d/default.conf, the following line gets added to the newly-generated server block:

    include /etc/nginx/vhost.d/default;

When letsencrypt-nginx-proxy-companion stops, /etc/nginx/vhost.d/default is removed, but the previously-generated /etc/nginx/conf.d/default.conf is left in place. The next time the nginx container is started, the include directive still exists, but /etc/nginx/vhost.d/default no longer does, so nginx fails to start.

docker-gen does notice when letsencrypt-nginx-proxy-companion is stopped, so it eventually regenerates a /etc/nginx/conf.d/default.conf without the include, but when both letsencrypt-nginx-proxy-companion and docker-gen are stopped in rapid succession, the regeneration doesn't have a chance to take place.

Since nginx starts fine with no /etc/nginx/conf.d/default.conf at all, and the file will get regenerated anyway within a few seconds of letsencrypt-nginx-proxy-companion stopping (if only that one container is being stopped), might it be helpful to automatically remove /etc/nginx/conf.d/default.conf in addition to /etc/nginx/vhost.d/default when letsencrypt-nginx-proxy-companion is stopped?

All 7 comments

Hi, actually I'm getting the same error as well recently. I found that default.conf is pointing to another non existing .conf. Deleting it before starting again seems to resolve this issue. I've yet to dig deeper.

The first time the nginx container starts, /etc/nginx/conf.d/default.conf contains default configuration from the nginx image, and starts up successfully.

/etc/nginx/vhost.d/default is later created by letsencrypt-nginx-proxy-companion, and if that file exists while docker-gen parses the template to regenerate /etc/nginx/conf.d/default.conf, the following line gets added to the newly-generated server block:

    include /etc/nginx/vhost.d/default;

When letsencrypt-nginx-proxy-companion stops, /etc/nginx/vhost.d/default is removed, but the previously-generated /etc/nginx/conf.d/default.conf is left in place. The next time the nginx container is started, the include directive still exists, but /etc/nginx/vhost.d/default no longer does, so nginx fails to start.

docker-gen does notice when letsencrypt-nginx-proxy-companion is stopped, so it eventually regenerates a /etc/nginx/conf.d/default.conf without the include, but when both letsencrypt-nginx-proxy-companion and docker-gen are stopped in rapid succession, the regeneration doesn't have a chance to take place.

Since nginx starts fine with no /etc/nginx/conf.d/default.conf at all, and the file will get regenerated anyway within a few seconds of letsencrypt-nginx-proxy-companion stopping (if only that one container is being stopped), might it be helpful to automatically remove /etc/nginx/conf.d/default.conf in addition to /etc/nginx/vhost.d/default when letsencrypt-nginx-proxy-companion is stopped?

+1

Same issue here. I have to delete nginx, nginx-gen before a restart (up > down > up). Please let me know if I can help with debuging. I can share my docker-compose files (edited)

+1

@JrCs The fact that the nginx container can start outside of the control of the nginx-gen container seems like asking for errors to me. I'd much rather see nginx (or some plugin) be able to evaluate a script to generate the config each time it runs, much like a lot of JS tools now use JS files for config instead of JSON.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bassail picture bassail  路  4Comments

DatAres37 picture DatAres37  路  5Comments

MarcSN311 picture MarcSN311  路  5Comments

maitrungduc1410 picture maitrungduc1410  路  5Comments

SuperRoach picture SuperRoach  路  5Comments