diff --git a/examples/customization/README.md b/examples/customization/README.md index 2cb4b521f5..2dad3ac04d 100644 --- a/examples/customization/README.md +++ b/examples/customization/README.md @@ -40,6 +40,7 @@ The table below summarizes some of the options. More options (extensions) are av | `nginx.org/listen-ports` | N/A | Configures HTTP ports that NGINX will listen on. | `[80]` | | `nginx.org/listen-ports-ssl` | N/A | Configures HTTPS ports that NGINX will listen on. | `[443]` | | N/A | `worker-processes` | Sets the value of the [worker_processes](http://nginx.org/en/docs/ngx_core_module.html#worker_processes) directive. | `auto` | +| N/A | `worker-connections` | Sets the value of the [worker_connections](http://nginx.org/en/docs/ngx_core_module.html#worker_connections) directive. | `1024` | | N/A | `worker-cpu-affinity` | Sets the value of the [worker_cpu_affinity](http://nginx.org/en/docs/ngx_core_module.html#worker_cpu_affinity) directive. | N/A | | N/A | `worker-shutdown-timeout` | Sets the value of the [worker_shutdown_timeout](http://nginx.org/en/docs/ngx_core_module.html#worker_shutdown_timeout) directive. | N/A | | `nginx.org/keepalive` | `keepalive` | Sets the value of the [keepalive](http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive) directive. Note that `proxy_set_header Connection "";` is added to the generated configuration when the value > 0. | `0` | diff --git a/examples/customization/nginx-config.yaml b/examples/customization/nginx-config.yaml index e7285b6ee2..3a27316caf 100644 --- a/examples/customization/nginx-config.yaml +++ b/examples/customization/nginx-config.yaml @@ -48,6 +48,7 @@ data: proxy_temp_path /var/nginx/proxy_temp; charset koi8-r; worker-processes: "1" # default is "auto". Sets the value of the worker_processes directive. See http://nginx.org/en/docs/ngx_core_module.html#worker_processes + worker-connections: "10240" # default is "1024". Sets the value of the worker_connections directive. See http://nginx.org/en/docs/ngx_core_module.html#worker_connections worker-cpu-affinity: "auto" # No default. Sets the value of the worker_cpu_affinity directive. See http://nginx.org/en/docs/ngx_core_module.html#worker_cpu_affinity worker-shutdown-timeout: "5m" # No default. Sets the value of the worker_shutdown_timeout directive. See http://nginx.org/en/docs/ngx_core_module.html#worker_shutdown_timeout keepalive: "32" # default is 0. When > 0, sets the value of the keepalive directive and adds 'proxy_set_header Connection "";' to a location block. See http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive diff --git a/nginx-controller/controller/controller.go b/nginx-controller/controller/controller.go index 9763734639..a2e46831e6 100644 --- a/nginx-controller/controller/controller.go +++ b/nginx-controller/controller/controller.go @@ -595,6 +595,9 @@ func (lbc *LoadBalancerController) syncCfgm(task Task) { if workerShutdownTimeout, exists := cfgm.Data["worker-shutdown-timeout"]; exists { cfg.MainWorkerShutdownTimeout = workerShutdownTimeout } + if workerConnections, exists := cfgm.Data["worker-connections"]; exists { + cfg.MainWorkerConnections = workerConnections + } if keepalive, exists, err := nginx.GetMapKeyAsInt(cfgm.Data, "keepalive", cfgm); exists { if err != nil { glog.Error(err) diff --git a/nginx-controller/nginx/config.go b/nginx-controller/nginx/config.go index 3c7f18c05e..343c931ffe 100644 --- a/nginx-controller/nginx/config.go +++ b/nginx-controller/nginx/config.go @@ -30,6 +30,7 @@ type Config struct { MainWorkerProcesses string MainWorkerCPUAffinity string MainWorkerShutdownTimeout string + MainWorkerConnections string Keepalive int64 // http://nginx.org/en/docs/http/ngx_http_realip_module.html @@ -63,6 +64,7 @@ func NewDefaultConfig() *Config { MainServerNamesHashMaxSize: "512", ProxyBuffering: true, MainWorkerProcesses: "auto", + MainWorkerConnections: "1024", HSTSMaxAge: 2592000, Ports: []int{80}, SSLPorts: []int{443}, diff --git a/nginx-controller/nginx/configurator.go b/nginx-controller/nginx/configurator.go index b8db4653e9..86c4f929ed 100644 --- a/nginx-controller/nginx/configurator.go +++ b/nginx-controller/nginx/configurator.go @@ -709,6 +709,7 @@ func (cnf *Configurator) UpdateConfig(config *Config, ingExes []*IngressEx) erro WorkerProcesses: config.MainWorkerProcesses, WorkerCPUAffinity: config.MainWorkerCPUAffinity, WorkerShutdownTimeout: config.MainWorkerShutdownTimeout, + WorkerConnections: config.MainWorkerConnections, } cnf.nginx.UpdateMainConfigFile(mainCfg) diff --git a/nginx-controller/nginx/nginx.go b/nginx-controller/nginx/nginx.go index 94dc25d7f4..eb338efd15 100644 --- a/nginx-controller/nginx/nginx.go +++ b/nginx-controller/nginx/nginx.go @@ -119,6 +119,7 @@ type NginxMainConfig struct { WorkerProcesses string WorkerCPUAffinity string WorkerShutdownTimeout string + WorkerConnections string } // NewUpstreamWithDefaultServer creates an upstream with the default server. @@ -146,6 +147,7 @@ func NewNginxController(nginxConfPath string, local bool, healthStatus bool, ngi ServerNamesHashMaxSize: NewDefaultConfig().MainServerNamesHashMaxSize, ServerTokens: NewDefaultConfig().ServerTokens, WorkerProcesses: NewDefaultConfig().MainWorkerProcesses, + WorkerConnections: NewDefaultConfig().MainWorkerConnections, } ngxc.UpdateMainConfigFile(cfg) diff --git a/nginx-controller/nginx/templates/nginx-plus.tmpl b/nginx-controller/nginx/templates/nginx-plus.tmpl index 1abb86a2cf..8ff346fc2a 100644 --- a/nginx-controller/nginx/templates/nginx-plus.tmpl +++ b/nginx-controller/nginx/templates/nginx-plus.tmpl @@ -17,7 +17,7 @@ pid /var/run/nginx.pid; {{- end}} events { - worker_connections 1024; + worker_connections {{.WorkerConnections}}; } diff --git a/nginx-controller/nginx/templates/nginx.tmpl b/nginx-controller/nginx/templates/nginx.tmpl index cd9d603f5c..fd8c8431ed 100644 --- a/nginx-controller/nginx/templates/nginx.tmpl +++ b/nginx-controller/nginx/templates/nginx.tmpl @@ -16,7 +16,7 @@ pid /var/run/nginx.pid; {{- end}} events { - worker_connections 1024; + worker_connections {{.WorkerConnections}}; } diff --git a/nginx-controller/nginx/templates/templates_test.go b/nginx-controller/nginx/templates/templates_test.go index 9a14badd42..23306abbaa 100644 --- a/nginx-controller/nginx/templates/templates_test.go +++ b/nginx-controller/nginx/templates/templates_test.go @@ -57,6 +57,7 @@ var mainCfg = nginx.NginxMainConfig{ WorkerProcesses: "auto", WorkerCPUAffinity: "auto", WorkerShutdownTimeout: "1m", + WorkerConnections: "1024", } func TestIngressForNGINXPlus(t *testing.T) {