Skip to content

Commit aad4fc9

Browse files
authored
Allow default_server listeners to be customised (#4464)
1 parent 801746a commit aad4fc9

File tree

15 files changed

+450
-16
lines changed

15 files changed

+450
-16
lines changed

charts/nginx-ingress/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ The following tables lists the configurable parameters of the NGINX Ingress Cont
452452
|`controller.podDisruptionBudget.maxUnavailable` | The number of Ingress Controller pods that can be unavailable. This is a mutually exclusive setting with "minAvailable". | 0 |
453453
|`controller.strategy` | Specifies the strategy used to replace old Pods with new ones. Docs for [Deployment update strategy](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy) and [Daemonset update strategy](https://kubernetes.io/docs/tasks/manage-daemon/update-daemon-set/#daemonset-update-strategy) | {} |
454454
|`controller.disableIPV6` | Disable IPV6 listeners explicitly for nodes that do not support the IPV6 stack. | false |
455+
|`controller.defaultHTTPListenerPort` | Sets the port for the HTTP `default_server` listener. | 80 |
456+
|`controller.defaultHTTPSListenerPort` | Sets the port for the HTTPS `default_server` listener. | 443 |
455457
|`controller.readOnlyRootFilesystem` | Configure root filesystem as read-only and add volumes for temporary data. | false |
456458
|`rbac.create` | Configures RBAC. | true |
457459
|`prometheus.create` | Expose NGINX or NGINX Plus metrics in the Prometheus format. | true |

charts/nginx-ingress/templates/controller-daemonset.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ spec:
237237
- -enable-cert-manager={{ .Values.controller.enableCertManager }}
238238
- -enable-oidc={{ .Values.controller.enableOIDC }}
239239
- -enable-external-dns={{ .Values.controller.enableExternalDNS }}
240+
- -default-http-listener-port={{ .Values.controller.defaultHTTPListenerPort}}
241+
- -default-https-listener-port={{ .Values.controller.defaultHTTPSListenerPort}}
240242
{{- if .Values.controller.globalConfiguration.create }}
241243
- -global-configuration=$(POD_NAMESPACE)/{{ include "nginx-ingress.controller.fullname" . }}
242244
{{- end }}

charts/nginx-ingress/templates/controller-deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ spec:
244244
- -enable-cert-manager={{ .Values.controller.enableCertManager }}
245245
- -enable-oidc={{ .Values.controller.enableOIDC }}
246246
- -enable-external-dns={{ .Values.controller.enableExternalDNS }}
247+
- -default-http-listener-port={{ .Values.controller.defaultHTTPListenerPort}}
248+
- -default-https-listener-port={{ .Values.controller.defaultHTTPSListenerPort}}
247249
{{- if .Values.controller.globalConfiguration.create }}
248250
- -global-configuration=$(POD_NAMESPACE)/{{ include "nginx-ingress.controller.fullname" . }}
249251
{{- end }}

charts/nginx-ingress/values.schema.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,22 @@
12621262
false
12631263
]
12641264
},
1265+
"defaultHTTPListenerPort": {
1266+
"type": "integer",
1267+
"default": 80,
1268+
"title": "The defaultHTTPListenerPort",
1269+
"examples": [
1270+
80
1271+
]
1272+
},
1273+
"defaultHTTPSListenerPort": {
1274+
"type": "integer",
1275+
"default": 443,
1276+
"title": "The defaultHTTPSListenerPort",
1277+
"examples": [
1278+
443
1279+
]
1280+
},
12651281
"readOnlyRootFilesystem": {
12661282
"type": "boolean",
12671283
"default": false,
@@ -1411,6 +1427,8 @@
14111427
},
14121428
"enableLatencyMetrics": false,
14131429
"disableIPV6": false,
1430+
"defaultHTTPListenerPort": 80,
1431+
"defaultHTTPSListenerPort": 443,
14141432
"readOnlyRootFilesystem": false
14151433
}
14161434
]
@@ -1776,6 +1794,8 @@
17761794
},
17771795
"enableLatencyMetrics": false,
17781796
"disableIPV6": false,
1797+
"defaultHTTPListenerPort": 80,
1798+
"defaultHTTPSListenerPort": 443,
17791799
"readOnlyRootFilesystem": false
17801800
},
17811801
"rbac": {

charts/nginx-ingress/values.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,12 @@ controller:
443443
## Disable IPV6 listeners explicitly for nodes that do not support the IPV6 stack.
444444
disableIPV6: false
445445

446+
## Sets the port for the HTTP `default_server` listener.
447+
defaultHTTPListenerPort: 80
448+
449+
## Sets the port for the HTTPS `default_server` listener.
450+
defaultHTTPSListenerPort: 443
451+
446452
## Configure root filesystem as read-only and add volumes for temporary data.
447453
readOnlyRootFilesystem: false
448454

cmd/nginx-ingress/flags.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ var (
194194
disableIPV6 = flag.Bool("disable-ipv6", false,
195195
`Disable IPV6 listeners explicitly for nodes that do not support the IPV6 stack`)
196196

197+
defaultHTTPListenerPort = flag.Int("default-http-listener-port", 80, "Sets a custom port for the HTTP NGINX `default_server`. [1024 - 65535]")
198+
199+
defaultHTTPSListenerPort = flag.Int("default-https-listener-port", 443, "Sets a custom port for the HTTPS `default_server`. [1024 - 65535]")
200+
197201
startupCheckFn func() error
198202
)
199203

cmd/nginx-ingress/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ func main() {
9090

9191
staticCfgParams := &configs.StaticConfigParams{
9292
DisableIPV6: *disableIPV6,
93+
DefaultHTTPListenerPort: *defaultHTTPListenerPort,
94+
DefaultHTTPSListenerPort: *defaultHTTPSListenerPort,
9395
HealthStatus: *healthStatus,
9496
HealthStatusURI: *healthStatusURI,
9597
NginxStatus: *nginxStatus,

docs/content/configuration/global-configuration/command-line-arguments.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,3 +508,19 @@ Disable IPV6 listeners explicitly for nodes that do not support the IPV6 stack.
508508
Default `false`.
509509
 
510510
<a name="cmdoption-disable-ipv6"></a>
511+
512+
### -default-http-listener-port
513+
514+
Sets the port for the HTTP `default_server` listener.
515+
516+
Default `80`.
517+
&nbsp;
518+
<a name="cmdoption-default-http-listener-port"></a>
519+
520+
### -default-https-listener-port
521+
522+
Sets the port for the HTTPS `default_server` listener.
523+
524+
Default `443`.
525+
&nbsp;
526+
<a name="cmdoption-default-https-listener-port"></a>

internal/configs/config_params.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ type ConfigParams struct {
114114
// StaticConfigParams holds immutable NGINX configuration parameters that affect the main NGINX config.
115115
type StaticConfigParams struct {
116116
DisableIPV6 bool
117+
DefaultHTTPListenerPort int
118+
DefaultHTTPSListenerPort int
117119
HealthStatus bool
118120
HealthStatusURI string
119121
NginxStatus bool

internal/configs/configmaps.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ func GenerateNginxMainConfig(staticCfgParams *StaticConfigParams, config *Config
514514
DefaultServerAccessLogOff: config.DefaultServerAccessLogOff,
515515
DefaultServerReturn: config.DefaultServerReturn,
516516
DisableIPV6: staticCfgParams.DisableIPV6,
517+
DefaultHTTPListenerPort: staticCfgParams.DefaultHTTPListenerPort,
518+
DefaultHTTPSListenerPort: staticCfgParams.DefaultHTTPSListenerPort,
517519
ErrorLogLevel: config.MainErrorLogLevel,
518520
HealthStatus: staticCfgParams.HealthStatus,
519521
HealthStatusURI: staticCfgParams.HealthStatusURI,

0 commit comments

Comments
 (0)