Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow default_server listeners to be customised #4464

Merged
merged 18 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add CLI arguments for configuring ports for default server
  • Loading branch information
shaun-nx committed Sep 29, 2023
commit 06f7992e67f627e6ab09e139c99d4b7fb8836ef2
4 changes: 4 additions & 0 deletions cmd/nginx-ingress/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ var (
disableIPV6 = flag.Bool("disable-ipv6", false,
`Disable IPV6 listeners explicitly for nodes that do not support the IPV6 stack`)

defaultServerHTTPPort = flag.Int("default-server-http-port", 80, "Sets a custom port for the HTTP NGINX `default_server`. [1024 - 65535]")

defaultServerHTTPSPort = flag.Int("default-server-https-port", 443, "Sets a custom port for the HTTPS `default_server`. [1024 - 65535]")

startupCheckFn func() error
)

Expand Down
2 changes: 2 additions & 0 deletions cmd/nginx-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ func main() {

staticCfgParams := &configs.StaticConfigParams{
DisableIPV6: *disableIPV6,
DefaultServerHTTPPort: *defaultServerHTTPPort,
DefaultServerHTTPSPort: *defaultServerHTTPSPort,
HealthStatus: *healthStatus,
HealthStatusURI: *healthStatusURI,
NginxStatus: *nginxStatus,
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 @@ -114,6 +114,8 @@ type ConfigParams struct {
// StaticConfigParams holds immutable NGINX configuration parameters that affect the main NGINX config.
type StaticConfigParams struct {
DisableIPV6 bool
DefaultServerHTTPPort int
DefaultServerHTTPSPort int
HealthStatus bool
HealthStatusURI string
NginxStatus bool
Expand Down
2 changes: 2 additions & 0 deletions internal/configs/configmaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ func GenerateNginxMainConfig(staticCfgParams *StaticConfigParams, config *Config
DefaultServerAccessLogOff: config.DefaultServerAccessLogOff,
DefaultServerReturn: config.DefaultServerReturn,
DisableIPV6: staticCfgParams.DisableIPV6,
DefaultServerHTTPPort: staticCfgParams.DefaultServerHTTPPort,
DefaultServerHTTPSPort: staticCfgParams.DefaultServerHTTPSPort,
ErrorLogLevel: config.MainErrorLogLevel,
HealthStatus: staticCfgParams.HealthStatus,
HealthStatusURI: staticCfgParams.HealthStatusURI,
Expand Down
2 changes: 2 additions & 0 deletions internal/configs/version1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ type MainConfig struct {
DefaultServerAccessLogOff bool
DefaultServerReturn string
DisableIPV6 bool
DefaultServerHTTPPort int
DefaultServerHTTPSPort int
ErrorLogLevel string
HealthStatus bool
HealthStatusURI string
Expand Down
8 changes: 4 additions & 4 deletions internal/configs/version1/nginx-plus.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,16 @@ http {
set $resource_namespace "";
set $service "";

listen 80 default_server{{if .ProxyProtocol}} proxy_protocol{{end}};
{{if not .DisableIPV6}}listen [::]:80 default_server{{if .ProxyProtocol}} proxy_protocol{{end}};{{end}}
listen {{ .DefaultServerHTTPPort }} default_server{{if .ProxyProtocol}} proxy_protocol{{end}};
{{if not .DisableIPV6}}listen [::]:{{ .DefaultServerHTTPPort }} default_server{{if .ProxyProtocol}} proxy_protocol{{end}};{{end}}

{{if .TLSPassthrough}}
listen unix:/var/lib/nginx/passthrough-https.sock ssl default_server{{if .HTTP2}} http2{{end}} proxy_protocol;
set_real_ip_from unix:;
real_ip_header proxy_protocol;
{{else}}
listen 443 ssl default_server{{if .HTTP2}} http2{{end}}{{if .ProxyProtocol}} proxy_protocol{{end}};
{{if not .DisableIPV6}}listen [::]:443 ssl default_server{{if .HTTP2}} http2{{end}}{{if .ProxyProtocol}} proxy_protocol{{end}};{{end}}
listen {{ .DefaultServerHTTPSPort }} ssl default_server{{if .HTTP2}} http2{{end}}{{if .ProxyProtocol}} proxy_protocol{{end}};
{{if not .DisableIPV6}}listen [::]:{{ .DefaultServerHTTPSPort }} ssl default_server{{if .HTTP2}} http2{{end}}{{if .ProxyProtocol}} proxy_protocol{{end}};{{end}}
{{end}}

{{if .SSLRejectHandshake}}
Expand Down
8 changes: 4 additions & 4 deletions internal/configs/version1/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ http {
set $resource_namespace "";
set $service "";

listen 80 default_server{{if .ProxyProtocol}} proxy_protocol{{end}};
{{if not .DisableIPV6}}listen [::]:80 default_server{{if .ProxyProtocol}} proxy_protocol{{end}};{{end}}
listen {{ .DefaultServerHTTPPort}} default_server{{if .ProxyProtocol}} proxy_protocol{{end}};
{{if not .DisableIPV6}}listen [::]:{{ .DefaultServerHTTPPort}} default_server{{if .ProxyProtocol}} proxy_protocol{{end}};{{end}}

{{if .TLSPassthrough}}
listen unix:/var/lib/nginx/passthrough-https.sock ssl default_server{{if .HTTP2}} http2{{end}} proxy_protocol;
set_real_ip_from unix:;
real_ip_header proxy_protocol;
{{else}}
listen 443 ssl default_server{{if .HTTP2}} http2{{end}}{{if .ProxyProtocol}} proxy_protocol{{end}};
{{if not .DisableIPV6}}listen [::]:443 ssl default_server{{if .HTTP2}} http2{{end}}{{if .ProxyProtocol}} proxy_protocol{{end}};{{end}}
listen {{ .DefaultServerHTTPSPort}} ssl default_server{{if .HTTP2}} http2{{end}}{{if .ProxyProtocol}} proxy_protocol{{end}};
{{if not .DisableIPV6}}listen [::]:{{ .DefaultServerHTTPSPort}} ssl default_server{{if .HTTP2}} http2{{end}}{{if .ProxyProtocol}} proxy_protocol{{end}};{{end}}
{{end}}

{{if .SSLRejectHandshake}}
Expand Down
Loading