I have an Nginx ingress controller set up on my kubernetes cluster, which by default does an https redirect for any requests that it receives, so http://example.com
is automatically forwarded on to https://example.com
.
I now have a host that I need to serve over http and not https, essentially excluding it from the ssl redirect. What I have found is that I can disable the ssl redirect across the whole ingress, but not for a specific host.
My Ingress yaml:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress
annotations:
kubernetes.io/ingress.class: nginx
spec:
tls:
- hosts:
- mysslsite.co.uk
secretName: tls-secret
rules:
- host: my-ssl-site.co.uk
http:
paths:
- path: /
backend:
serviceName: my-service
servicePort: 80
- host: my-non-ssl-site.co.uk
http:
paths:
- path: /
backend:
serviceName: my-other-service
servicePort: 80
My Config Map:
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app: nginx-ingress
chart: nginx-ingress-0.28.3
component: controller
heritage: Tiller
release: nginx-ingress
name: undercooked-moth-nginx-ingress-controller
namespace: default
data:
proxy-buffer-size: "512k"
client-header-buffer-size: "512k"
proxy-body-size: "100m"
large-client-header-buffers: "4 512k"
http2-max-field-size: "512k"
http2-max-header-size: "512k"
fastcgi_buffers: "16 16k"
fastcgi_buffer_size: "32k"
What I have tried:
Attempt to turn off ssl redirect across the board and set a rule to redirect to the site requiring ssl to https by setting the annotation
nginx.ingress.kubernetes.io/ssl-redirect: "false"
and adding the following config snippet:nginx.ingress.kubernetes.io/configuration-snippet: | if ($host = 'my-ssl-site.co.uk' ) { rewrite ^ https://my-ssl-site.co.uk$request_uri permanent; }
This does remove the https redirect but results in a
too many redirects
error for the site requiring ssl.Attempted to add rules in the ConfigMap as per this answer to turn off ssl redirect and handle the conditional redirect in a server config snippet but this still resulted in an ssl redirect.
Tried to add a second ingress controller so that one could have ssl redirect enabled and the other one could have it turned off. I created the controller but I think I also need to create a second nginx ingress and configure and label the apps that will be returned to each? This seems like overkill when all I want to do is exclude one service on the cluster from the ssl redirect.
Is there anything obvious I am missing? It feels as though it shouldn't be this hard to add a simple rule to exclude one host from the ssl-redirect.