diff --git a/docs/user-guide/nginx-configuration/configmap.md b/docs/user-guide/nginx-configuration/configmap.md index 688c8012c5..28e4275774 100755 --- a/docs/user-guide/nginx-configuration/configmap.md +++ b/docs/user-guide/nginx-configuration/configmap.md @@ -183,6 +183,7 @@ The following table shows a configuration option's name, type, and the default v |[block-user-agents](#block-user-agents)|[]string|""| |[block-referers](#block-referers)|[]string|""| |[proxy-ssl-location-only](#proxy-ssl-location-only)|bool|"false"| +|[default-type](#default-type)|string|"text/html"| ## add-headers @@ -1084,3 +1085,11 @@ _References:_ Set if proxy-ssl parameters should be applied only on locations and not on servers. _**default:**_ is disabled + +## default-type + +Sets the default MIME type of a response. +_**default:**_ text/html + +_References:_ +[http://nginx.org/en/docs/http/ngx_http_core_module.html#default_type](http://nginx.org/en/docs/http/ngx_http_core_module.html#default_type) diff --git a/internal/ingress/controller/config/config.go b/internal/ingress/controller/config/config.go index 5f164e7465..b73cdde1da 100644 --- a/internal/ingress/controller/config/config.go +++ b/internal/ingress/controller/config/config.go @@ -671,6 +671,11 @@ type Configuration struct { // proxy-ssl-* annotations are applied on on location level only in the nginx.conf file // Default is that those are applied on server level, too ProxySSLLocationOnly bool `json:"proxy-ssl-location-only"` + + // DefaultType Sets the default MIME type of a response. + // http://nginx.org/en/docs/http/ngx_http_core_module.html#default_type + // Default: text/html + DefaultType string `json:"default-type"` } // NewDefault returns the default nginx configuration @@ -815,6 +820,7 @@ func NewDefault() Configuration { NoAuthLocations: "/.well-known/acme-challenge", GlobalExternalAuth: defGlobalExternalAuth, ProxySSLLocationOnly: false, + DefaultType: "text/html", } if klog.V(5) { diff --git a/internal/ingress/controller/template/configmap_test.go b/internal/ingress/controller/template/configmap_test.go index 2cc13c5231..e4101fb078 100644 --- a/internal/ingress/controller/template/configmap_test.go +++ b/internal/ingress/controller/template/configmap_test.go @@ -74,6 +74,7 @@ func TestMergeConfigMapToStruct(t *testing.T) { "nginx-status-ipv6-whitelist": "::1,2001::/16", "proxy-add-original-uri-header": "false", "disable-ipv6-dns": "true", + "default-type": "text/plain", } def := config.NewDefault() def.CustomHTTPErrors = []int{300, 400} @@ -97,6 +98,7 @@ func TestMergeConfigMapToStruct(t *testing.T) { def.ProxyAddOriginalURIHeader = false def.LuaSharedDicts = defaultLuaSharedDicts def.DisableIpv6DNS = true + def.DefaultType = "text/plain" hash, err := hashstructure.Hash(def, &hashstructure.HashOptions{ TagName: "json", diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index f828b1a17a..5888cf30c6 100755 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -279,7 +279,7 @@ http { {{ buildOpentracing $cfg $servers }} include /etc/nginx/mime.types; - default_type text/html; + default_type {{ $cfg.DefaultType }}; {{ if $cfg.EnableBrotli }} brotli on;