Skip to content

[bitnami/nginx] Add worker_processes env var#91159

Open
jhthompson wants to merge 6 commits intobitnami:mainfrom
jhthompson:main
Open

[bitnami/nginx] Add worker_processes env var#91159
jhthompson wants to merge 6 commits intobitnami:mainfrom
jhthompson:main

Conversation

@jhthompson
Copy link
Copy Markdown

@jhthompson jhthompson commented Feb 27, 2026

Description of the change

Add a NGINX_WORKER_PROCESSES environment variable to control the value of the Nginx worker_processes directive.

Benefits

Ability to better control resource usage

Nginx's worker_processes auto creates too many worker processes in certain deployments. This change provides an easy hook to manually set the number to a more sensible value. From a currently open issue on Nginx itself:

Currently, if one uses worker_processes auto;, nginx uses sysconf(_SC_NPROCESSORS_ONLN) to detect the number of available processes.

In environments, such as Kubernetes or OpenShift, this causes issues, as it returns the cores available to the system and not the actual services available to the service.

This is a solved problem in the docker-nginx image by providing an entrypoint script to "tune" the value to something more appropriate, but adding a similar approach here feels heavy-handed.

Corrects existing documentation

It is not possible to override worker_processes via the listed method in the Readme, as Nginx errors with a "duplicate directive" since it ends up being present twice.

Possible drawbacks

If NGINX_WORKER_PROCESSES is currently set in any deployments that use this image, there may be unexpected behavior.

Applicable issues

n/a

Additional information

Various issues across several Nginx projects are related to this:

@github-actions github-actions bot added nginx triage Triage is needed labels Feb 27, 2026
@github-actions github-actions bot requested a review from javsalgar February 27, 2026 19:58
Signed-off-by: Jeremy Thompson <23730407+jhthompson@users.noreply.github.com>
@carrodher carrodher added verify Execute verification workflow for these changes in-progress labels Mar 2, 2026
@github-actions github-actions bot removed the triage Triage is needed label Mar 2, 2026
@github-actions github-actions bot removed the request for review from javsalgar March 2, 2026 09:26
@github-actions github-actions bot requested a review from fmulero March 2, 2026 09:26
@jhthompson
Copy link
Copy Markdown
Author

jhthompson commented Mar 2, 2026

Some outputs from my local testing (if relevant). All commands ran from bitnami/nginx/1.29/debian-12):

Building the image locally:

docker build -t nginx-local:$(git rev-parse --short HEAD) --build-arg TARGETARCH=amd64 .

No env var

docker run nginx-local:80ceba9418a   
nginx 20:28:22.37 INFO  ==> 
nginx 20:28:22.37 INFO  ==> Welcome to the Bitnami nginx container
nginx 20:28:22.37 INFO  ==> 
nginx 20:28:22.38 INFO  ==> ** Starting NGINX setup **
nginx 20:28:22.40 INFO  ==> Validating settings in NGINX_* env vars
Certificate request self-signature ok
subject=CN = example.com
nginx 20:28:23.91 INFO  ==> No custom scripts in /docker-entrypoint-initdb.d
nginx 20:28:23.92 INFO  ==> Initializing NGINX
realpath: /bitnami/nginx/conf/vhosts: No such file or directory
nginx 20:28:23.96 INFO  ==> ** NGINX setup finished! **

nginx 20:28:23.98 INFO  ==> ** Starting NGINX **

(from running container):

nginx -T
nginx: the configuration file /opt/bitnami/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/bitnami/nginx/conf/nginx.conf test is successful
# configuration file /opt/bitnami/nginx/conf/nginx.conf:
# Based on https://www.nginx.com/resources/wiki/start/topics/examples/full/#nginx-conf
# user              www www;  ## Default: nobody

worker_processes  auto; # <------------------- relevant line here
error_log         "/opt/bitnami/nginx/logs/error.log";
pid               "/opt/bitnami/nginx/tmp/nginx.pid";

include  "/opt/bitnami/nginx/conf/context.d/main/*.conf";
# ... more below ...

With valid env var

docker run -e NGINX_WORKER_PROCESSES=1 nginx-local:80ceba9418a
nginx 20:33:37.26 INFO  ==> 
nginx 20:33:37.26 INFO  ==> Welcome to the Bitnami nginx container
nginx 20:33:37.27 INFO  ==> 
nginx 20:33:37.27 INFO  ==> ** Starting NGINX setup **
nginx 20:33:37.30 INFO  ==> Validating settings in NGINX_* env vars
Certificate request self-signature ok
subject=CN = example.com
nginx 20:33:41.25 INFO  ==> No custom scripts in /docker-entrypoint-initdb.d
nginx 20:33:41.25 INFO  ==> Initializing NGINX
realpath: /bitnami/nginx/conf/vhosts: No such file or directory
nginx 20:33:41.30 INFO  ==> ** NGINX setup finished! **

nginx 20:33:41.32 INFO  ==> ** Starting NGINX **

(from running container):

nginx -T
nginx: the configuration file /opt/bitnami/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/bitnami/nginx/conf/nginx.conf test is successful
# configuration file /opt/bitnami/nginx/conf/nginx.conf:
# Based on https://www.nginx.com/resources/wiki/start/topics/examples/full/#nginx-conf
# user              www www;  ## Default: nobody

worker_processes  1; # <------------------- relevant line here
error_log         "/opt/bitnami/nginx/logs/error.log";
pid               "/opt/bitnami/nginx/tmp/nginx.pid";

include  "/opt/bitnami/nginx/conf/context.d/main/*.conf";
# ... more below ...

With invalid env var

docker run -e NGINX_WORKER_PROCESSES=aut nginx-local:80ceba9418a
nginx 20:35:31.23 INFO  ==> 
nginx 20:35:31.23 INFO  ==> Welcome to the Bitnami nginx container
nginx 20:35:31.24 INFO  ==> 
nginx 20:35:31.24 INFO  ==> ** Starting NGINX setup **
nginx 20:35:31.26 INFO  ==> Validating settings in NGINX_* env vars
nginx 20:35:31.26 ERROR ==> The allowed values for NGINX_WORKER_PROCESSES are: auto or a positive integer
docker run -e NGINX_WORKER_PROCESSES=-2 nginx-local:80ceba9418a
nginx 20:35:46.13 INFO  ==> 
nginx 20:35:46.13 INFO  ==> Welcome to the Bitnami nginx container
nginx 20:35:46.13 INFO  ==> 
nginx 20:35:46.14 INFO  ==> ** Starting NGINX setup **
nginx 20:35:46.16 INFO  ==> Validating settings in NGINX_* env vars
nginx 20:35:46.16 ERROR ==> The allowed values for NGINX_WORKER_PROCESSES are: auto or a positive integer

Signed-off-by: Jeremy Thompson <23730407+jhthompson@users.noreply.github.com>
Signed-off-by: Jeremy Thompson <23730407+jhthompson@users.noreply.github.com>
@jhthompson
Copy link
Copy Markdown
Author

@fmulero @carrodher sorry for the ping! Just checking in to see if anyone has had a chance to look at this yet, and if there's anything I should add/remove/change.

@jhthompson
Copy link
Copy Markdown
Author

@fmulero @carrodher sorry for another ping - is there anything I can do to help move things along on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in-progress nginx verify Execute verification workflow for these changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants