How to persistently set Nginx's worker processes?

gotdoge

Registered
Feb 5, 2021
3
0
1
US
cPanel Access Level
Root Administrator
I'm trying to set worker_processes to auto, but it keeps being reverted. I know that certain directives can be set in ea-nginx/settings.json, but worker_processes doesn't appear to be one of them and setting it in conf.d/modules/*.conf doesn't take precedence from the tests I've ran.

Is there any way to set that or override other core Nginx directives that are not supported in settings.json?

cPanel/WHM version 11.106.0.9, Nginx version 1.23.1
 

gotdoge

Registered
Feb 5, 2021
3
0
1
US
cPanel Access Level
Root Administrator
Hey there! Have you tried using the details under the Global Configuration in this section? NGINX with Reverse Proxy | cPanel & WHM Documentation

This will let you create configuration files that area read globally for all accounts.
Yes, but that doesn't work as worker_processes doesn't belong in a server block. To be clear, I'm referring to this directive: Core functionality

Tried adding a code block here to show the top 15 lines of /etc/nginx/nginx.conf, but getting a 403 upon submitting a post reply with it. I noticed that worker_connections seems to be preserved when set to a custom setting, but worker_processes is still reverted back to 1. I had changed worker_processes to auto again and worker_connections's 1024 to 4096, but only the former was reverted.

Being able to adjust this directive is a pretty integral part of configuring Nginx so I believe cPanel should look at incorporating some form of managing more of the configuration natively.
 

Thimempapa

Member
Oct 4, 2022
6
0
1
Germany
cPanel Access Level
Root Administrator
I have the same problem.
How to set Worker Processes ??
I just can have 1, like for one CPU Core. Manual says one Worker per CPU core but the setting in /etc/nginx.conf keeps reverting.
 

Thimempapa

Member
Oct 4, 2022
6
0
1
Germany
cPanel Access Level
Root Administrator
There´s a solution now. after contacting support, this here work for me:

# cp -vi /etc/nginx/nginx.conf{,.bkp}
# cat /etc/nginx/ea-nginx/settings.json
{
"apache_port" : "81",
"apache_port_ip" : "127.0.0.1",
"apache_ssl_port" : "444",
"apache_ssl_port_ip" : "127.0.0.1",
"client_max_body_size" : "128m",
"worker_processes" : "2"
}

After "worker_processes" : "2" has been appended to /etc/nginx/ea-nginx/settings.json as outlined above, you would also need to rebuild the configuration:
/scripts/ea-nginx config --all

Then you can verify the worker_processes is retained in the NGINX configuration with the following commands:
# cat /etc/nginx/ea-nginx/settings.json
{
"apache_port" : "81",
"apache_port_ip" : "127.0.0.1",
"apache_ssl_port" : "444",
"apache_ssl_port_ip" : "127.0.0.1",
"client_max_body_size" : "128m",
"worker_processes" : "2"
}
# grep worker /etc/nginx/nginx.conf
worker_processes 2;
worker_shutdown_timeout 10s;
worker_rlimit_nofile 65536;
worker_connections 4096;
#

Modify settings.json did not work because the reconfig must be run afterwards. so the solution to edit settings.json is working very well ;)