From e78ad92c87bd9fb1d2cc8342af48425289c46b34 Mon Sep 17 00:00:00 2001 From: Petr Gregor Date: Wed, 11 Oct 2017 15:24:33 +0200 Subject: [PATCH] Change alias behaviour not to create new server section needlessly --- configuration.md | 2 +- rootfs/etc/nginx/template/nginx.tmpl | 16 +--------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/configuration.md b/configuration.md index caf718ec6..bc948d47c 100644 --- a/configuration.md +++ b/configuration.md @@ -201,7 +201,7 @@ For more information please check https://enable-cors.org/server_nginx.html ### Server Alias To add Server Aliases to an Ingress rule add the annotation `ingress.kubernetes.io/server-alias: ""`. -This will create a server with the same configuration, but a different server_name as the provided host. +This will create a server with two server_names (hostname and alias) *Note:* A server-alias name cannot conflict with the hostname of an existing server. If it does the server-alias annotation will be ignored. If a server-alias is created and later a new server with the same hostname is created diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index 6f101aa84..caaec9282 100644 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -362,26 +362,12 @@ http { {{ range $index, $server := $servers }} server { - server_name {{ $server.Hostname }}; + server_name {{ $server.Hostname }} {{ $server.Alias }}; {{ template "SERVER" serverConfig $all $server }} {{ template "CUSTOM_ERRORS" $all }} } - - {{ if $server.Alias }} - server { - 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 }} - } - {{ end }} {{ end }} # default server, used for NGINX healthcheck and access to nginx stats