How to force https on ingress?

1/18/2017

I'm on digital ocean, using the default ingress. The only documentation I can find on the topic is for other cloud hosts.

The documentation is unclear, it reads like http:// will automatically be redirected to https:// but I'm simply not seeing that behavior. https:// is responding perfectly, http:// is not being listened to at all (fails to connect)

-- Michael Draper
kubernetes

1 Answer

1/18/2017

To force HTTPS you have to run it through an nginx (or apache or another http server), catch the event in there and re-direct it back.

So you ingress: Accept http & https (correct)

Your nginx container after the ingress add this to one of your configuration files:

listen 80 default_server;
server_name  _;
if ($http_x_forwarded_proto = "http") {
    return 301 https://$host$request_uri;
}

This then redirects the session to https thus forcing https only. However depending on the load balancer used/configured, you might have to inspect the x_forwarded options from nginx in a bit more detail.

-- Norbert van Nobelen
Source: StackOverflow