我有一个面向 dotnet 1.1.0 的 ASP.NET Core Angular 应用程序。
我在我的 Linux Ubuntu 16.04 上安装了 Nginx,并配置了 nginx confog 文件如下:
server {
listen 80;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
和myapp.services文件如下:
[Unit]
Description=Sample application.
[Service]
Type=simple
WorkingDirectory=/var/myappfolder
ExecStart=/usr/bin/dotnet /var/myappfolder/myapp.dll
#User=web
[Install]
WantedBy=multi-user.target
我用一个简单的示例应用程序测试了这个设置,它运行良好。但是,一旦我将适当的应用程序部署到/var/myappfolder 并配置
systemclt start mywebsite
systemclt daemon_reload
然后检查
systemclt status mywebsite
我收到这个错误:
jtrade.service - Sample application. Loaded: loaded (/lib/systemd/system/jtrade.service; disabled; vendor preset: enabled) Active: failed (Result: signal) since Wed 2017-08-30 18:08:08 UTC; 9s ago Process: 4640 ExecStart=/usr/bin/dotnet /var/jtrade/jtradep.dll (code=killed, signal=ABRT) Main PID: 4640 (code=killed, signal=ABRT)
Aug 30 18:08:08 localhost dotnet[4640]: at Microsoft.DotNet.Configurer.NuGetCacheSentinel.get_NuGetCachePath()
Aug 30 18:08:08 localhost dotnet[4640]: at Microsoft.DotNet.Configurer.NuGetCacheSentinel.Exists()
Aug 30 18:08:08 localhost dotnet[4640]: at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.ShouldPrimeNugetCache()
Aug 30 18:08:08 localhost dotnet[4640]: at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
Aug 30 18:08:08 localhost dotnet[4640]: at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentinel)
Aug 30 18:08:08 localhost dotnet[4640]: at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
Aug 30 18:08:08 localhost dotnet[4640]: at Microsoft.DotNet.Cli.Program.Main(String[] args)
Aug 30 18:08:08 localhost systemd[1]: jtrade.service: Main process exited, code=killed, status=6/ABRT
Aug 30 18:08:08 localhost systemd[1]: jtrade.service: Unit entered failed state.
Aug 30 18:08:08 localhost systemd[1]: jtrade.service: Failed with result 'signal'.
所以我使用 journalctl -u myappname
深入调试这个错误并获得了一些更有用的信息:
Started Sample application..
Aug 31 05:13:34 localhost dotnet[10290]: Unhandled Exception: System.InvalidOperationException: Required environment variable 'HOME' is not set. Try setting 'HOME' and running the operation again.
Aug 31 05:13:34 localhost dotnet[10290]: at NuGet.Common.NuGetEnvironment.GetValueOrThrowMissingEnvVar(Func`1 getValue, String name)
Aug 31 05:13:34 localhost dotnet[10290]: at NuGet.Common.NuGetEnvironment.GetHome() Aug 31 05:13:34 localhost dotnet[10290]: at NuGet.Common.NuGetEnvironment.<>c.<.cctor>b__12_0()
Aug 31 05:13:34 localhost dotnet[10290]: at System.Lazy`1.CreateValue()
Aug 31 05:13:34 localhost dotnet[10290]: --- End of stack trace from previous location where exception was thrown ---
Aug 31 05:13:34 localhost dotnet[10290]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Aug 31 05:13:34 localhost dotnet[10290]: at System.Lazy`1.get_Value()
Aug 31 05:13:34 localhost dotnet[10290]: at NuGet.Common.NuGetEnvironment.GetFolderPath(SpecialFolder folder)
Aug 31 05:13:34 localhost dotnet[10290]: at NuGet.Common.NuGetEnvironment.GetFolderPath(NuGetFolderPath folder)
Aug 31 05:13:34 localhost dotnet[10290]: at NuGet.Configuration.SettingsUtility.GetGlobalPackagesFolder(ISettings settings)
Aug 31 05:13:34 localhost dotnet[10290]: at NuGet.Configuration.NuGetPathContext.Create(ISettings settings)
Aug 31 05:13:34 localhost dotnet[10290]: at Microsoft.DotNet.Configurer.NuGetCacheSentinel.get_NuGetCachePath()
Aug 31 05:13:34 localhost dotnet[10290]: at Microsoft.DotNet.Configurer.NuGetCacheSentinel.Exists()
Aug 31 05:13:34 localhost dotnet[10290]: at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.ShouldPrimeNugetCache()
Aug 31 05:13:34 localhost dotnet[10290]: at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
Aug 31 05:13:34 localhost dotnet[10290]: at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentinel)
Aug 31 05:13:34 localhost dotnet[10290]: at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
Aug 31 05:13:34 localhost dotnet[10290]: at Microsoft.DotNet.Cli.Program.Main(String[] args)
Aug 31 05:13:34 localhost systemd[1]: jtrade.service: Main process exited, code=killed, status=6/ABRT
Aug 31 05:13:34 localhost systemd[1]: jtrade.service: Unit entered failed state.
Aug 31 05:13:34 localhost systemd[1]: jtrade.service: Failed with result 'signal'.
如果我运行 printenv 查看我的环境变量,我会发现 HOME=/root
也许它应该设置成别的东西?
最佳答案
显然我刚刚写了 环境=HOME=/root 在 .service 文件中,一切都开始工作
关于linux - ASP.NET Core Angular 应用程序无法在带有 Nginx 和 Systemd 的 Ubuntu 16.04 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45967246/