我在ubuntu 14.04 vm上运行了dotnet core 1.0。我正在尝试为部署过程编写一个upstart脚本:
start on filesystem and started networking
respawn
chdir /home/dotnetuser/dotnetportal/
exec sudo /usr/bin/dotnet restore
exec sudo /usr/bin/dotnet run
运行此服务后,我验证日志并获得通常预期的内容(来自本地/开发vm测试):
Hosting environment: Production
Content root path: /home/dotnetuser/dotnetportal
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
我的域和ssl的nginx反向代理上有localhost:5000:
server {
# Enable HTTP/2
listen 443 ssl; #http2;
listen [::]:443 ssl; #http2;
server_name portal.secret.com;
# use the lets encrypt certificates
ssl_certificate /etc/letsencrypt/live/portal.secret.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/portal.secret.com/privkey.pem;
# include the SSL configuration from cipherli.st
include snippets/ssl_params.conf;
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;
}
}
然而,当我卷曲https://portal.secret.com/时,我再次验证日志,并且出现了一堆编译器错误。
请记住,直接从工作生产文件夹运行dotnet并且我能够访问该网站时,我不会收到任何错误。
我尝试从服务运行网站时的日志是:
an unhandled exception has occurred: Can not find compilation library location for package ' microsoft.aspnetcore.antiforgery'
18 System.InvalidOperationException: Can not find compilation library location for package 'microsoft .aspnetcore.antiforgery'
19 at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths()
20 at System.Linq.Enumerable.<SelectManyIterator>d__157`2.MoveNext()
21 at Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeatureProvider.PopulateFeature( IEnumerable`1 parts, MetadataReferenceFeature feature ETC.....
是否有任何人只有在我启动服务而不是直接运行命令时才能了解为什么会发生这种情况?
更新:这是我的Project.json
{
"userSecretsId": "xxxxx",
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
},
"System.Runtime.Loader": "4.0.0",
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Routing": "1.0.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.EntityFrameworkCore.Sqlite": "1.0.1",
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-update1",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
"version": "1.0.0-preview2-update1",
"type": "build"
},
"MongoDB.Driver" : "2.3.0"
},
"tools": {
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview2-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
},
"Microsoft.Extensions.SecretManager.Tools": {
"version": "1.0.0-preview2-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
]
}
},
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"**/*.cshtml",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
},
"tooling": {
"defaultNamespace": "WebApplication"
}
}
答案 0 :(得分:0)
我通过删除/ tmp / NuGetScratch文件夹解决了这个问题,并且还明确地告诉linux哪个用户运行应用程序。更新的服务配置脚本是:
start on filesystem and started networking
respawn
setuid dotnetuser
env HOME=/home/dotnetuser
exec rm -rf /tmp/NuGetScratch/
chdir /home/dotnetuser/apps/dotnetportal
exec dotnet restore
exec dotnet run
问题是.net没有编译,因为在我删除的目录(tmp / NuGetScratch)中找到的nuget锁文件导致了文件权限问题。我想现在.net希望你以root身份运行 - 在这里发现:https://github.com/dotnet/dotnet-docker/issues/78(NuGet缓存填充失败,因为/ tmp / NuGetScratch由root或其他su拥有)