Azure Kubernetes NGINX Ingress redirect to www stopped working

6/25/2019

I've set up and NGINX Ingress on Azure Kubernetes with an annotation to redirect from example.com to https://www.example.com.

The current configuration used to work perfectly but no longer works. Configuration is as follows:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: myapp-ingress
  annotations:
    nginx.ingress.kubernetes.io/configuration-snippet: |
      if ($host = 'example.com' ) {
        rewrite ^ https://www.example.com$request_uri permanent;
      }
    nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
spec:
  tls:
    - hosts:
      - example.com
      - www.example.com
      secretName: myapp-secret
  rules:
  - host: www.example.com
    http:
      paths:
      - backend:
          serviceName: myapp-prod-service
          servicePort: 80
  - host: domain.com
    http:
      paths:
      - backend:
          serviceName: myapp-prod-service
          servicePort: 80
-- Ben Gannaway
azure-kubernetes
kubernetes
kubernetes-ingress
nginx-ingress

1 Answer

6/25/2019

This only wasn't working because of the internal network setup where I was working. The configuration above is correct and works.

-- Ben Gannaway
Source: StackOverflow