.NET 8 应用程序仅监听 http 端口

问题描述 投票:0回答:1

我有一个看似基本的问题,但是在搜索并添加

https_port
作为环境变量、
appsettings
顶级属性以及其他尝试之后,每当我将应用程序部署到 Rancher 时,它只侦听端口 8080 上的 http。

这是一个简单的Web应用程序,除了通过keycloak测试授权之外没有任何实际功能,因此所有流量的需求都是https。

我希望启动日志包含“正在侦听:https://[::]:8081”或 https 流量的其他端口。

相反,我得到:

warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
2024-09-20T09:50:14.146416699Z       Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed. For more information go to https://aka.ms/aspnet/dataprotectionwarning
2024-09-20T09:50:14.540842462Z warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
2024-09-20T09:50:14.540881640Z       No XML encryptor configured. Key {b25d69c8-24c9-4281-b5df-71ab43c8182f} may be persisted to storage in unencrypted form.
2024-09-20T09:50:15.340432431Z info: Microsoft.Hosting.Lifetime[14]
2024-09-20T09:50:15.340467342Z       Now listening on: http://[::]:8080
2024-09-20T09:50:15.340471006Z info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
2024-09-20T09:50:15.340475874Z info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
2024-09-20T09:50:15.340480847Z info: Microsoft.Hosting.Lifetime[0]
2024-09-20T09:50:15.340483241Z       Content root path: /app

我希望我遗漏了一些关于 .NET 8 的明显内容。

我的部署文件如下所示(其中一些值替换为虚拟值):

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myPOCsite
  namespace: backend
spec:
  selector:
    matchLabels:
      app: myPOCsite
  replicas: 1
  template:
    metadata:
      labels:
        app: myPOCsite
        log: "yes"
    spec:
      containers:
      - name: myPOCsite
        image: myimageurl
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8081
        resources:
          limits:
            memory: "100Mi"
            cpu: "80m"
          requests:
            memory: "60Mi"
            cpu: "40m"
      hostname: myPOCsite
      imagePullSecrets:
      - name: regsecret
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: myPOCsite
  name: myPOCsite
  namespace: backend
spec:
  ports:
  - port: 443
    protocol: TCP
    name: https
    targetPort: 8081
  selector:
    app: myPOCsite
  type: ClusterIP
docker kubernetes .net-8.0 rancher
1个回答
1
投票

在他们的 Docker 镜像中,Microsoft 将环境变量

ASPNETCORE_HTTP_PORTS
设置为 8080,这会使您的应用程序侦听该端口上的 HTTP。他们的
runtime-deps
图像的 Dockerfile 是 here,该图像用作
aspnet
图像的基础。

侦听端口 8080 上的 HTTP 流量是 Docker 化 ASP.NET 应用程序的默认行为。

如果您希望它侦听另一个端口和/或侦听 HTTPS,您需要按照此处所述进行配置。

请注意,由于 Microsoft 使用环境变量配置端口,因此无法使用 appsettings.json 配置端口,因为环境变量会覆盖 appsettings。

© www.soinside.com 2019 - 2024. All rights reserved.