I have a AWS NLB with SSL termination -> kubernetes nginx ingress controller configuration and I want to be able to redirect only certain specific domains from http to https. I am using the following server-snippet in my Ingress resource:
nginx.ingress.kubernetes.io/server-snippet: |
if ($scheme = "http") {
return 308 https://$host$request_uri;
}
It actually generates the correct nginx.conf file but it keeps redirecting both http and https requests.
server {
server_name mydomain.com ;
listen 80 ;
listen 443 ssl http2 ;
set $proxy_upstream_name "-";
ssl_certificate_by_lua_block {
certificate.call()
}
# Custom code snippet configured for host mydomain.com
if ($scheme = "http") {
return 308 https://$host$request_uri;
}
...
}
I also tried with the annotations "force-ssl-redirect" and "ssl-redirect" but obtained the same result. Am I missing something in this configuration? If not and this is not a working feature, is there another way I can do the redirect?