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

Changing worker_processes value in nginx configuration #21

Closed
naktinis opened this issue Jan 11, 2018 · 8 comments
Closed

Changing worker_processes value in nginx configuration #21

naktinis opened this issue Jan 11, 2018 · 8 comments

Comments

@naktinis
Copy link
Contributor

In the default /etc/nginx/nginx.conf worker_processes is set to 1. However, I'd like to change this value.

I would suggest one of these approaches:

  1. set the value to auto (so it is set to the number of CPU cores)
  2. create an ENV variable NGINX_WORKER_PROCESSES (which can be set in Dockerfiles) and which is written into the config.
@tiangolo
Copy link
Owner

Good idea!

I like the 2 option.

That way the NGINX_WORKER_PROCESSES env var could be set to auto and it would achieve the same as the option 1.

Do you want to create a Pull Request?

@naktinis
Copy link
Contributor Author

Yes, I think I could create a PR.

What approach would you prefer for setting the value in the configuration? Should I store a modified /etc/nginx/nginx.conf based on the nginx default and then copy it to the image, or replace the specific line using sed (which is what I'm doing at the moment)? Also, let me know if you have other ideas.

@tiangolo
Copy link
Owner

I think we could set a NGINX_WORKER_PROCESSES to be the default (1) in the Dockerfile.

Then read that in the entrypoint.sh and write an additional config file like /etc/nginx/conf.d/worker_processes.conf

Very much in the same way it's done for NGINX_MAX_UPLOAD.

Here in the Dockerfile: https://github.com/tiangolo/uwsgi-nginx-docker/blob/master/python3.6/Dockerfile#L124

And here in the entrypoint.sh: https://github.com/tiangolo/uwsgi-nginx-docker/blob/master/python3.6/entrypoint.sh#L5

@naktinis
Copy link
Contributor Author

I thik client_max_body_size parameter can be set like this, because its context is defined as http, server, location. However, worker_processes context is main.

Files like /etc/nginx/conf.d/worker_processes.conf are imported into the http context (see the include /etc/nginx/conf.d/*.conf; directive in /etc/nginx/nginx.conf). You will not be able to set worker_processes there as you'll get the "worker_processes" directive is not allowed here error.

Also, you can not simply append a line to /etc/nginx/nginx.conf, because the value will then be defined twice and you'll get the "worker_processes" directive is duplicate error.

@naktinis naktinis reopened this Jan 15, 2018
@tiangolo
Copy link
Owner

Yep. You're right. We would have to sed it. Like with USE_LISTEN_PORT but in the main nginx.conf.

@naktinis
Copy link
Contributor Author

Created a pull request (#22). Let me know what you think.

@naktinis
Copy link
Contributor Author

Any updates on this?

@tiangolo
Copy link
Owner

tiangolo commented Feb 4, 2018

Thanks! Great work. Your PR is merged 🎉 .

@tiangolo tiangolo closed this as completed Feb 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants