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
感谢您的回复。我忘了添加这个,这是在后台运行。我只使用Nginx作为反向代理服务器。我在/etc/systemd/system/kestrel-filmer.service设置了'Environment = ASPNETCORE_ENVIRONMENT = Production' –
@DominikVit你需要为ASP.NET Core进程设置'ASPNETCORE_ENVIRONMENT',而不是Nginx进程。正如@Tseng所说的,你需要在全局进行设置,或者作为选项,你可以将环境名称作为参数传递给你的.net核心应用程序。有关详细信息,请参阅下面的SO问题:[在命令行中运行.net核心应用程序开发](http://stackoverflow.com/q/43412065/2833802) – Set
感谢您的回复。我尝试过但没有任何成功。它仍然是一样的。 –