docker-openresty
docker-openresty copied to clipboard
About nginx.conf and conf.d/default.conf
I have tried forllowing:
- Added my nginx.conf, however - still default.conf was read, although I never included it. Like this include is forced somewhere
- Deleted
defult.conf
. Nothing works. - Moved all
server
directives from mynginx.config
todefault.conf
- now things started working. Even though I never includeddefault.conf
in mynginx.conf
.
Why is this happening?
Related to https://github.com/openresty/openresty/issues/463
Can you paste how you are running this?
Actually, adding
command: /usr/local/openresty/bin/openresty -c /etc/nginx/nginx.conf -g daemon\ off;
in docker-compose I was capable to use my nginx.conf
. Without it it was using configs.d/default.conf
[EDIT: typo here, what I wanted to say is cong.d
] even though I had my nginx.conf
which did not include default.conf
at all.
The docs describe how to get your Nginx config files are handled by the image. There's various ways to handle them, depending on your setup. One of them is what you did -- specifiying your own command.
If you didn't specify, then it defaults to /etc/nginx/conf.d/default.conf
which also does include /etc/nginx/conf.d/*.conf;
. [If you saying configs.d
is not a typo, then something else is wrong.]
If you are going to use your own nginx.conf
, you'll probably want to make sure you set up logging , as described in your other ticket. You can either explicitly set logs to /dev/stdout
or pointing your logs to /usr/local/openresty/nginx/logs/access.log
, which then symlinks to stdout (and similar with stderr).
Related to https://github.com/openresty/docker-openresty/issues/91
@neomantra I did not specify, but I did add nginx.conf
via docker mapped volume, and I thought that it would be used as soon as it is present in /etc/nginx
. Apparently - this was not the case, and in addition to adding nginx.conf
file we must explicitly tell to OpenResty to use it with a command -c /etc/nginx/nginx.conf
. I was surprised, because this was not a case for mainstream NginX container - it was sufficient just to add nginx.conf
via mapped volume, and NginX in container will emmediately start using this one.
I just commented out access_log
and error_log
directives in my nginx.conf
, hoping that by default OpenResty will fallback to /usr/local/openresty/nginx/logs/access.log
and /usr/local/openresty/nginx/logs/error.log
which in turn are symlinked to /dev/stdout
and /dev/stderr` respectively. As explained in https://github.com/openresty/docker-openresty/issues/91 I am seeing problems with this.
Additionally I tried explicitly setting in nginx.conf
:
access_log /dev/stdout;
error_log /dev/stderr;
but effects were exactly the same - logs not shown until container is restarted. Then all the previous logs are spin on the screes - like they were buffered somewhere or something. And from there on logging works as it should.
Is it possible that docker buffers the stdout
, or that OpenResty logs are buffered somewhere and not flushed to stdout
?
You needed to add -c /etc/nginx/nginx.conf
because OpenResty by default looks at /usr/local/openresty/nginx/conf/nginx.conf
. OpenResty (upstram) intentionally has a different base install prefix than Nginx (simplifies side-by-side installs on bare-metal). The Docker images follow this. Similarly, the output log paths are different (e.g. /usr/local/openresty/nginx/logs/access.log
). Nginx's default log output locations are logs/access.log
, so it is a relative thing (I forget if relative to nginx prefix or working dir).
The buffering or whatever is weird, let's try to figure it out on the other issue.
Can I then just keep the default command and mapp my local nginx.conf
to /usr/local/openresty/nginx/conf/nginx.conf
in container? Will the OpenResty use thihs one, and not conf.d/default.conf
?
Yes, exactly. If you install or bind-mount it to /usr/local/openresty/nginx/conf/nginx.conf
, OpenResty will load your file by default. If you are not trying to be simultaneously compatible with non-OpenResty Nginx, I think that should work fine. And all the relative stuff should fall in place.
@neomantra I have removed
command: /usr/local/openresty/bin/openresty -c /etc/nginx/nginx.conf -g daemon\ off;
and used volume mount of custom nginx.conf
in the default OpenResty location as you proposed in docker-compose.
This worked, and moreover - this fixed logging issue mentioned in https://github.com/openresty/docker-openresty/issues/91
This part of the document is very confusing, so consider optimizing the document based on the answers here
I no longer use OpenResty nor operate instances, so I am removed from high-quality operational discussions. But I do continue to manage the project, especially updating to new versions, watching for CVEs, etc.
I'd be happy to include any documentation updates that experienced users can provide. We can discuss it in a PR. I agree the README has a lot of cruft in it!
If there is a PR for a new nginx.conf
setup per this thread, I will help review and shepherd it. I don't have the capacity to test it fully and would need community-driven feedback (as we do on this issue!)
We are near 100M image pulls and must be careful with what is released. Thanks all for your interest in progressing this. I am going to re-open this issue in this context.