2017-04-19 125 views
0

我想弄清楚這個bug一個星期,但我仍然無法找到錯誤。ASP .NET核心 - Linux的nginx ASPNETCORE_ENVIROMENT錯誤

系統我目前運行的是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--> 

ASLO我我使用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 

Error that is showing up

回答

1

當然也不會工作,因爲你沒有設置環境變量。

  • web.config僅適用於IIS。 nginx無法做任何事情。
  • launchSettings.json僅用於Visual Studio在按F5時啓動項目。

你必須考慮ngnix文檔瞭解如何設置環境變量或者設置在殼一個全局變量(這將是有效的服務器上的所有應用程序)一樣export ASPNETCORE_ENVIRONMENT=Development

+0

感謝您的回覆。我忘了添加這個,這是在後臺運行。我只使用Nginx作爲反向代理服務器。我在/etc/systemd/system/kestrel-filmer.service設置了'Environment = ASPNETCORE_ENVIRONMENT = Production' –

+0

@DominikVit你需要爲ASP.NET Core進程設置'ASPNETCORE_ENVIRONMENT',而不是Nginx進程。正如@Tseng所說的,你需要在全局進行設置,或者作爲選項,你可以將環境名稱作爲參數傳遞給你的.net核心應用程序。有關詳細信息,請參閱下面的SO問題:[在命令行中運行.net核心應用程序開發](http://stackoverflow.com/q/43412065/2833802) – Set

+0

感謝您的回覆。我嘗試過但沒有任何成功。它仍然是一樣的。 –