How can I disable automatic https redirect for nginx ingress controller?

5/19/2019

I enabled the ingress addon for my local minikube and created a custom pod, service and ingress. After that I added the ingress host to my hosts file where it points to the minikube ip so that I can reach it with my browser. When accessing the url, the browser is telling my that because of a "HTTP Strict Transport Security (HSTS)" header I was redirected to the https version of that url. Firefox and chrome do not allow me to continue because they say that the certificate (Kubernetes Ingress Controller Fake Certificate) is only valid for the url "ingress.local". With IE11 I can accept the risk and actually continue. What I can do to prevent getting redirected to https? I don't want https, only http. Here are the yaml files of my service and my ingress.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: foobar-ingress
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: foobar.app
    http:
      paths:
      - path: /
        backend:
          serviceName: foobar-frontend
          servicePort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: foobar-frontend
spec:
  ports:
  - port: 80
    targetPort: 8080
  selector:
    app: foobar-frontend
-- Matthew Darton
kubernetes
minikube
nginx-ingress

2 Answers

5/21/2019

It seems I already had it right. The browser was just brutally caching the HSTS header which is why I always got redirected. Even cleaning the cache did not work. So I had to change my ingress to another name and then it worked.

-- Matthew Darton
Source: StackOverflow

5/20/2019

You need to disable ssl-redirect in Nginx configmap (usually named nginx-configuration in ingress-nginx namespace) like this:

kind: ConfigMap
metadata:
  labels:
    app: ingress-nginx
  name: nginx-configuration
  namespace: ingress-nginx
data:
  ssl-redirect: "false"

After that you need to restart Nginx ingress pod.

Also you may need to clear browser redirect cache: How long does Chrome remember a 301 redirect?

-- Vasily Angapov
Source: StackOverflow