diff --git a/controllers/nginx/configuration.md b/controllers/nginx/configuration.md index 064458a9cbe..b76bf1955d0 100644 --- a/controllers/nginx/configuration.md +++ b/controllers/nginx/configuration.md @@ -537,6 +537,16 @@ Default: 9411 **zipkin-service-name:** specifies the service name to use for any traces created Default: nginx +**http-snippet:** adds custom configuration to the http section of the nginx configuration +Default: "" + +**server-snippet:** adds custom configuration to all the servers in the nginx configuration +Default: "" + +**location-snippet:** adds custom configuration to all the locations in the nginx configuration +Default: "" + + ### Default configuration options The following table shows the options, the default value and a description. diff --git a/controllers/nginx/pkg/config/config.go b/controllers/nginx/pkg/config/config.go index 764dfd88a35..3b4ddd6ec0e 100644 --- a/controllers/nginx/pkg/config/config.go +++ b/controllers/nginx/pkg/config/config.go @@ -391,6 +391,15 @@ type Configuration struct { // ZipkinServiceName specifies the service name to use for any traces created // Default: nginx ZipkinServiceName string `json:"zipkin-service-name"` + + // HTTPSnippet adds custom configuration to the http section of the nginx configuration + HTTPSnippet string `json:"http-snippet"` + + // ServerSnippet adds custom configuration to all the servers in the nginx configuration + ServerSnippet string `json:"server-snippet"` + + // LocationSnippet adds custom configuration to all the locations in the nginx configuration + LocationSnippet string `json:"location-snippet"` } // NewDefault returns the default nginx configuration diff --git a/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl b/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl index 88413515d25..2193e9ae402 100644 --- a/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl +++ b/controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl @@ -281,6 +281,11 @@ http { proxy_pass_header Server; {{ end }} + {{ if not (empty $cfg.HTTPSnippet) }} + # Custom code snippet configured in the configuration configmap + {{ $cfg.HTTPSnippet }}; + {{ end }} + {{ range $name, $upstream := $backends }} {{ if eq $upstream.SessionAffinity.AffinityType "cookie" }} upstream sticky-{{ $upstream.Name }} { @@ -394,6 +399,10 @@ http { server_name {{ $server.Alias }}; {{ template "SERVER" serverConfig $all $server }} + {{ if not (empty $cfg.ServerSnippet) }} + # Custom code snippet configured in the configuration configmap + {{ $cfg.ServerSnippet }}; + {{ end }} {{ template "CUSTOM_ERRORS" $all }} } @@ -808,6 +817,11 @@ stream { {{/* Add any additional configuration defined */}} {{ $location.ConfigurationSnippet }} + {{ if not (empty $all.Cfg.LocationSnippet) }} + # Custom code snippet configured in the configuration configmap + {{ $all.Cfg.LocationSnippet }}; + {{ end }} + {{/* if we are sending the request to a custom default backend, we add the required headers */}} {{ if (hasPrefix $location.Backend "custom-default-backend-") }} proxy_set_header X-Code 503;