Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About nginx.conf and conf.d/default.conf #90

Open
drasko opened this issue Mar 15, 2019 · 11 comments
Open

About nginx.conf and conf.d/default.conf #90

drasko opened this issue Mar 15, 2019 · 11 comments

Comments

@drasko
Copy link

drasko commented Mar 15, 2019

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 my nginx.config to default.conf - now things started working. Even though I never included default.conf in my nginx.conf.

Why is this happening?

@drasko
Copy link
Author

drasko commented Mar 15, 2019

Related to openresty/openresty#463

@neomantra
Copy link
Member

Can you paste how you are running this?

@drasko
Copy link
Author

drasko commented Mar 16, 2019

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.

@neomantra
Copy link
Member

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).

@drasko
Copy link
Author

drasko commented Mar 16, 2019

Related to #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 #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?

@neomantra
Copy link
Member

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.

@drasko
Copy link
Author

drasko commented Mar 16, 2019

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?

@neomantra
Copy link
Member

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.

@drasko
Copy link
Author

drasko commented Mar 17, 2019

@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 #91

@engvuchen
Copy link

This part of the document is very confusing, so consider optimizing the document based on the answers here

@neomantra
Copy link
Member

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.

@neomantra neomantra reopened this Feb 23, 2024
@neomantra neomantra changed the title About nginx.conf and conf.d/defualt.conf About nginx.conf and conf.d/default.conf Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants