<p>I have created a .NET Core microservice using Microsoft sign-in as explained <a href="https://stackoverflow.com/questions/69031953/how-to-set-the-redirect-uri-when-using-microsoft-sign-in-in-a-net-5-application">here</a>. When running it locally or in a local Docker container, everything is working as expected. However, when running in <a href="https://aws.amazon.com/eks/" rel="nofollow noreferrer">EKS</a>, I get an annoying warning message in the logs:</p>
<blockquote>
<p>Failed to determine the https port for redirect.</p>
</blockquote>
<p>This warning is shown in this picture shown below which also shows that I also checked which port numbers are used (only 80 for http). I would be nice if <code>netstat -tulp</code> would show a port number for https because then I can just set it in the application settings (<a href="https://learn.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?view=aspnetcore-2.2&amp;tabs=visual-studio#port-configuration" rel="nofollow noreferrer">as explained by the Microsoft docs</a>) ad resolve it directly.</p>
<p>The Microsoft docs clearly exlain what to do when</p>
<blockquote>
<p>The middleware logs the warning &quot;Failed to determine the https port
for redirect.&quot;</p>
</blockquote>
<p>but these do not make clear what to do if everything works fine in all environments except when running the application in EKS. Probably, I should do something in my EKS/Kubernetes configuration but I have no clue what to do.</p>
<p>Here is the service file:</p>
<p><a href="https://i.stack.imgur.com/qAF6T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qAF6T.png" alt="enter image description here" /></a></p>
<p>Here is the warning message shown in the logs.</p>
<p><a href="https://i.stack.imgur.com/IvKji.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IvKji.png" alt="enter image description here" /></a></p>
<p>How do I resolve the warning message?</p>

<p>I can see you are using <code>app.UseHsts();</code> in <code>Startup.cs</code> file which will force client to use https. See document <a href="https://learn.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?view=aspnetcore-5.0&amp;tabs=visual-studio#http-strict-transport-security-protocol-hsts" rel="nofollow noreferrer">here</a>.</p>
<p>But basic on your log <code>Now listening on: http://[::]:80</code>, your service only listening on http but not https.</p>
<p>Maybe You can try this</p>
<ol>
<li>Simply delete the code <code>app.UseHsts();</code> and use only http.</li>
<li>Enable https by config <code>spec.template.spec.containers.env</code> in k8s deployment.yaml. You will need a server tls cert in your container.</li>
</ol>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: webapi
  labels:
    app: weather-forecast
spec:
  replicas: 1
  selector:
    matchLabels:
      service: webapi
  template:
    metadata:
      labels:
        app: weather-forecast
        service: webapi
    spec:
      containers:
        - name: webapi
          image: exploredocker.azurecr.io/webapi:v1
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 80
              protocol: TCP
            - containerPort: 443
              protocol: TCP
          env:
            - name: ASPNETCORE_URLS
              value: https://+:443;http://+:80
            - name: ASPNETCORE_Kestrel__Certificates__Default__Path
              value: /https/server_cert.pfx
            - name: ASPNETCORE_Kestrel__Certificates__Default__Password
              value: password
</code></pre>
