nginx.ingress.kubernetes.io/force-ssl-redirect: "true"¶
Purpose: Forces HTTP traffic to redirect to HTTPS automatically.
In Gateway API, you need to create:
- A Gateway with both HTTP (port 80) and HTTPS (port 443) listeners
- An HTTPRoute attached to the HTTP listener that redirects to HTTPS
- An HTTPRoute attached to the HTTPS listener that routes to your backend
2. HTTPRoute for HTTP to HTTPS Redirect:
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: example-redirect
spec:
parentRefs:
- name: eg
sectionName: http # Attach to HTTP listener
hostnames:
- "www.example.com"
rules:
- filters:
- type: RequestRedirect
requestRedirect:
scheme: https
statusCode: 301 # Permanent redirect (default)
References: