【问题标题】:ASP .NET Core - Linux nginx ASPNETCORE_ENVIROMENT ErrorASP .NET Core - Linux nginx ASPNETCORE_ENVIROMENT 错误
【发布时间】:2017-09-15 23:00:53
【问题描述】:

我试图找出这个错误一周,但我仍然找不到错误。

我目前运行的系统是 Linux Ubuntu 16.04

我已在 launchSettings.json 中将所有内容设置为生产

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:51754/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Production"
      }
    },
    "FilmerCore": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Production"
      },
      "applicationUrl": "http://localhost:51755"
    }
  }
}

这是我的 web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\FilmerCore.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
    <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
      </environmentVariables>
    </aspNetCore>
  </system.webServer>

</configuration>
<!--ProjectGuid: 5be3ea4c-66c2-42b0-8583-29c6bf415674-->

另外,我使用 nginx 作为反向代理。主要配置是这样的

[Unit]
    Description=Filmer - .NET movie platform

    [Service]
    WorkingDirectory=/var/aspnetcore/filmer
    ExecStart=/usr/bin/dotnet /var/aspnetcore/filmer/FilmerCore.dll
    Restart=always
    RestartSec=10                                          # Restart service after 10 seconds if dotnet service crashes
    SyslogIdentifier=filmer
    User=www-data
    Environment=ASPNETCORE_ENVIRONMENT=Development 

    [Install]
    WantedBy=multi-user.target

【问题讨论】:

    标签: asp.net linux nginx asp.net-core asp.net-core-mvc


    【解决方案1】:

    当然不行,因为你没有设置环境变量。

    • web.config 仅适用于 IIS。 nginx 对此无能为力。
    • launchSettings.json 仅用于 Visual Studio 在您按 F5 时启动您的项目。

    您必须查看有关如何设置环境变量或在 shell 中设置全局变量(对服务器上的所有应用程序都有效)的 ngnix 文档,例如 export ASPNETCORE_ENVIRONMENT=Development

    【讨论】:

    • 感谢您的回复。我忘了添加这个,这是在后台运行的。我仅将 Nginx 用作反向代理服务器。我已经设置在 /etc/systemd/system/kestrel-filmer.service Environment=ASPNETCORE_ENVIRONMENT=Production
    • @DominikVit 您需要为 ASP.NET Core 进程设置 ASPNETCORE_ENVIRONMENT,而不是为 Nginx 进程设置。正如@Tseng 所说,您需要全局设置它,或者作为一个选项,您可以将环境名称作为参数传递给您的 .net 核心应用程序。有关详细信息,请参阅下一个 SO 问题:run .net core application in development from the command line
    • 感谢您的回复。我已经尝试过了,但没有任何成功。它仍然是一样的。
    猜你喜欢
    • 2019-10-05
    • 2020-06-06
    • 2021-07-21
    • 2018-12-20
    • 2020-04-03
    • 2021-07-31
    • 2017-11-23
    • 2022-07-13
    • 2018-12-12
    相关资源
    最近更新 更多