diff --git a/controllers/nginx/configuration.md b/controllers/nginx/configuration.md index c87011377..53cf62c27 100644 --- a/controllers/nginx/configuration.md +++ b/controllers/nginx/configuration.md @@ -487,6 +487,7 @@ The following table shows the options, the default value and a description. |ssl-session-timeout|10m| |use-gzip|"true"| |use-http2|"true"| +|upstream-keepalive-connections|"0" (disabled)| |variables-hash-bucket-size|64| |variables-hash-max-size|2048| |vts-status-zone-size|10m| diff --git a/controllers/nginx/pkg/config/config.go b/controllers/nginx/pkg/config/config.go index 6af823b10..1bfd2dd78 100644 --- a/controllers/nginx/pkg/config/config.go +++ b/controllers/nginx/pkg/config/config.go @@ -293,6 +293,14 @@ type Configuration struct { // Sets the maximum size of the variables hash table. // http://nginx.org/en/docs/http/ngx_http_map_module.html#variables_hash_max_size VariablesHashMaxSize int `json:"variables-hash-max-size,omitempty"` + + // Activates the cache for connections to upstream servers. + // The connections parameter sets the maximum number of idle keepalive connections to + // upstream servers that are preserved in the cache of each worker process. When this + // number is exceeded, the least recently used connections are closed. + // http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive + // Default: 0 (disabled) + UpstreamKeepaliveConnections int `json:"upstream-keepalive-connections,omitempty"` } // NewDefault returns the default nginx configuration @@ -351,6 +359,7 @@ func NewDefault() Configuration { WhitelistSourceRange: []string{}, SkipAccessLogURLs: []string{}, }, + UpstreamKeepaliveConnections: 0, } if glog.V(5) { diff --git a/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl b/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl index 99bc20765..f78aed02a 100644 --- a/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl +++ b/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl @@ -235,6 +235,11 @@ http { {{ $cfg.LoadBalanceAlgorithm }}; {{ end }} {{ end }} + + {{ if (gt $cfg.UpstreamKeepaliveConnections 0) }} + keepalive {{ $cfg.UpstreamKeepaliveConnections }}; + {{ end }} + {{ range $server := $upstream.Endpoints }}server {{ $server.Address | formatIP }}:{{ $server.Port }} max_fails={{ $server.MaxFails }} fail_timeout={{ $server.FailTimeout }}; {{ end }} }