Add support for Server Alias in Nginx

Adds support for server alias in nginx. Adds a new annotation
which allows us to specify a server alias that will be appended
to the server name.
This commit is contained in:
Fernando Diaz 2017-08-09 22:22:54 -05:00
parent 198c926bb9
commit ac504bdbc0
8 changed files with 146 additions and 4 deletions

View file

@ -64,7 +64,7 @@ The following annotations are supported:
|[ingress.kubernetes.io/upstream-max-fails](#custom-nginx-upstream-checks)|number|
|[ingress.kubernetes.io/upstream-fail-timeout](#custom-nginx-upstream-checks)|number|
|[ingress.kubernetes.io/whitelist-source-range](#whitelist-source-range)|CIDR|
|[ingress.kubernetes.io/server-alias](#server-alias)|string|
#### Custom NGINX template
@ -155,7 +155,7 @@ Please check the [tls-auth](/examples/auth/client-certs/nginx/README.md) example
### Configuration snippet
Using this annotion you can add additional configuration to the NGINX location. For example:
Using this annotation you can add additional configuration to the NGINX location. For example:
```
ingress.kubernetes.io/configuration-snippet: |
@ -167,6 +167,17 @@ ingress.kubernetes.io/configuration-snippet: |
To enable Cross-Origin Resource Sharing (CORS) in an Ingress rule add the annotation `ingress.kubernetes.io/enable-cors: "true"`. This will add a section in the server location enabling this functionality.
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: "<server-name_0>:<server-alias_0>;...;<server-name_n>:<server-alias_n>"`.
This will append a server-alias to the end of the server_name in the NGINX server. A server-alias can accept wildcards, but
it cannot accept port numbers.
The server-name must match a valid server within the ingress resource for it to append the server-alias. Multiple server-aliases
can be added for multiple server-names using `;` as a delimiter.
For more information please see http://nginx.org/en/docs/http/ngx_http_core_module.html#server_name
### External Authentication
To use an existing service that provides authentication the Ingress rule can be annotated with `ingress.kubernetes.io/auth-url` to indicate the URL where the HTTP request should be sent.

View file

@ -452,6 +452,7 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
IP: svc.Spec.ClusterIP,
Port: port,
ProxyProtocol: false,
})
}

View file

@ -295,7 +295,7 @@ http {
{{ $backlogSize := .BacklogSize }}
{{ range $index, $server := .Servers }}
server {
server_name {{ $server.Hostname }};
server_name {{ $server.Hostname }} {{ $server.Alias }};
listen 80{{ if $cfg.UseProxyProtocol }} proxy_protocol{{ end }}{{ if eq $server.Hostname "_"}} default_server reuseport backlog={{ $backlogSize }}{{end}};
{{ if $IsIPV6Enabled }}listen [::]:80{{ if $cfg.UseProxyProtocol }} proxy_protocol{{ end }}{{ if eq $server.Hostname "_"}} default_server reuseport backlog={{ $backlogSize }}{{ end }};{{ end }}
set $proxy_upstream_name "-";