首页 > 解决方案 > 如何配置 Kestrel Web 服务器以使用我的生产服务器的 IP 地址?

问题描述

目前我在 Ubuntu 服务器上运行 dotnet core mvc 3.1。当我运行应用程序时,我看到:

./MyApp.Web ASPNETCORE_ENVIRONMENT=Production ASPNETCORE_URLS=http://1.2.3.4/

info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /root/apps
^Cinfo: Microsoft.Hosting.Lifetime[0]

我有一个 appsettings.Product.json 文件也有:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "Redis": {
    "Host": "localhost",
    "Port": "6379"
  },
  "Kestrel": {
    "EndPoints": {
      "Http": {
        "Url": "http://1.2.3.4"
      }
    }
  }
}

我的 Program.cs 有:

    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }

我很困惑为什么没有使用 appsettings.Production.json 文件,以及为什么我传递的环境变量也没有被使用。

有什么帮助吗?

标签: .net-corekestrel-http-server

解决方案


推荐阅读