8000 Support custom return in the default server by 030 · Pull Request #1297 · nginx/kubernetes-ingress · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ See the doc about [VirtualServer and VirtualServerRoute resources](/nginx-ingres
- Enables or disables the `real_ip_recursive <https://nginx.org/en/docs/http/ngx_http_realip_module.html#real_ip_recursive>`_ directive.
- ``False``
-
* - ``default-server-return``
- Configures the `return <https://nginx.org/en/docs/http/ngx_http_rewrite_module.html#return>`_ directive in the default server, which handles a client request if none of the hosts of Ingress or VirtualServer resources match. The default value configures NGINX to return a 404 error page. You can configure a fixed response or a redirect. For example, ``default-server-return: 302 https://nginx.org`` will redirect a client to ``https://nginx.org``.
- ``404``
-
* - ``server-tokens``
- Enables or disables the `server_tokens <https://nginx.org/en/docs/http/ngx_http_core_module.html#server_tokens>`_ directive. Additionally, with the NGINX Plus, you can specify a custom string value, including the empty string value, which disables the emission of the “Server” field.
- ``True``
Expand Down
2 changes: 2 additions & 0 deletions internal/configs/config_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import conf_v1alpha1 "github.com/nginxinc/kubernetes-ingress/pkg/apis/configurat
type ConfigParams struct {
ClientMaxBodySize string
DefaultServerAccessLogOff bool
DefaultServerReturn string
FailTimeout string
HealthCheckEnabled bool
HealthCheckMandatory bool
Expand Down Expand Up @@ -131,6 +132,7 @@ type Listener struct {
// NewDefaultConfigParams creates a ConfigParams with default values.
func NewDefaultConfigParams() *ConfigParams {
return &ConfigParams{
DefaultServerReturn: "404",
ServerTokens: "on",
ProxyConnectTimeout: "60s",
ProxyReadTimeout: "60s",
Expand Down
5 changes: 5 additions & 0 deletions internal/configs/configmaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ func ParseConfigMap(cfgm *v1.ConfigMap, nginxPlus bool, hasAppProtect bool) *Con
}
}

if defaultServerReturn, exists := cfgm.Data["default-server-return"]; exists {
cfgParams.DefaultServerReturn = defaultServerReturn
}

if proxyBuffering, exists, err := GetMapKeyAsBool(cfgm.Data, "proxy-buffering", cfgm); exists {
if err != nil {
glog.Error(err)
Expand Down Expand Up @@ -497,6 +501,7 @@ func GenerateNginxMainConfig(staticCfgParams *StaticConfigParams, config *Config
nginxCfg := &version1.MainConfig{
AccessLogOff: config.MainAccessLogOff,
DefaultServerAccessLogOff: config.DefaultServerAccessLogOff,
DefaultServerReturn: config.DefaultServerReturn,
ErrorLogLevel: config.MainErrorLogLevel,
HealthStatus: staticCfgParams.HealthStatus,
HealthStatusURI: staticCfgParams.HealthStatusURI,
Expand Down
1 change: 1 addition & 0 deletions internal/configs/version1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ type Location struct {
type MainConfig struct {
AccessLogOff bool
DefaultServerAccessLogOff bool
DefaultServerReturn string
ErrorLogLevel string
HealthStatus bool
HealthStatusURI string
Expand Down
2 changes: 1 addition & 1 deletion internal/configs/version1/nginx-plus.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ http {
{{end}}

location / {
return 404;
return {{.DefaultServerReturn}};
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/configs/version1/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ http {
{{end}}

location / {
return 404;
return {{.DefaultServerReturn}};
}
}

Expand Down
0