<p>I have a service providing an API that I want to only be accessible over <code>https</code>. I don't want <code>http</code> to redirect to <code>https</code> because that will expose credentials and the caller won't notice. Better to get an error response.</p>
<p>How to do I configure my ingress.yaml? Note that I want to maintain the default 308 redirect from <code>http</code> to <code>https</code> for other services in the same cluster.</p>
<p>Thanks.</p>

<p>In the <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#server-side-https-enforcement-through-redirect" rel="nofollow noreferrer">documentation</a>: you can read the following sentence about HTTPS enforcement through redirect:</p>
<blockquote>
<p>By default the controller redirects (308) to HTTPS if TLS is enabled for that ingress. If you want to disable this behavior globally, you can use  <code>ssl-redirect: &quot;false&quot;</code>  in the NGINX  <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#ssl-redirect" rel="nofollow noreferrer">ConfigMap</a>.</p>
</blockquote>
<blockquote>
<p>To configure this feature for specific ingress resources, you can use the nginx.ingress.kubernetes.io/ssl-redirect: &quot;false&quot; annotation in the particular resource.</p>
</blockquote>
<p>You can also create two separate configurations: one with http and https and the other one only for http.</p>
<p>Using <a href="https://kubernetes.github.io/ingress-nginx/user-guide/multiple-ingress/" rel="nofollow noreferrer"><code>kubernetes.io/ingress.class</code></a> annotation you can choose the ingress controller to be used.</p>
<blockquote>
<p>This mechanism also provides users the ability to run <em>multiple</em> NGINX ingress controllers (e.g. one which serves public traffic, one which serves &quot;internal&quot; traffic).</p>
</blockquote>
<p>See also <a href="https://stackoverflow.com/questions/56302606/kubernetes-ingress-nginx-how-can-i-disable-listening-on-https-if-no-tls-config">this</a> and <a href="https://stackoverflow.com/questions/50087544/disable-ssl-redirect-for-kubernetes-nginx-ingress/50087545">this</a> similar questions.</p>
