.Net Core 3.1 Angular Starter在Linux上不提供静态文件
我正在尝试从DigitalOcean的虚拟服务器为.NETCore3.1Angular项目提供服务 首先,我为我的子域democlient.mydomain.com设置了一个Nginx服务器块,并在/var/www/democlient.mydomain.com中创建了一个简单的html文件。 然后,我使用Letsencrypt的certbot启用了SSL。 当我转到时,我会看到html文件的内容 然后,我在我的Windows 10 PC上使用.NET Core 3.1 Angular模板创建了一个新项目.Net Core 3.1 Angular Starter在Linux上不提供静态文件,angular,asp.net-core,nginx,Angular,Asp.net Core,Nginx,我正在尝试从DigitalOcean的虚拟服务器为.NETCore3.1Angular项目提供服务 首先,我为我的子域democlient.mydomain.com设置了一个Nginx服务器块,并在/var/www/democlient.mydomain.com中创建了一个简单的html文件。 然后,我使用Letsencrypt的certbot启用了SSL。 当我转到时,我会看到html文件的内容 然后,我在我的Windows 10 PC上使用.NET Core 3.1 Angular模板创建了
dotnet new angular -o DemoClient
它在Windows 10上本地运行。我将它克隆到我位于DigitalOcean的Ubuntu 18.04机器上,并在/var/www/democlient.mydomain.com中创建了一个指向bin/Release/netcoreapp3.1/publish文件夹的符号链接。
我已经使用
dotnet publish --configuration Release
创建了一个系统服务
[Unit]
Description=.NET Web App - DemoClient
[Service]
WorkingDirectory=/var/www/democlient.mydomain.com
ExecStart=/usr/bin/dotnet /var/www/democlient.mydomain.com/DemoClient.dll
Restart=always
RestartSec=10
SyslogIdentifier=democlient
User=berten
Environment=ASPNETCORE_ENVIRONMENT=Debug
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
服务状态输出:
● democlient.service - .NET Web App - DemoClient
Loaded: loaded (/etc/systemd/system/democlient.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-04-03 09:47:03 UTC; 2h 40min ago
Main PID: 3137 (dotnet)
Tasks: 14 (limit: 1151)
CGroup: /system.slice/democlient.service
└─3137 /usr/bin/dotnet /var/www/democlient.muydomain.com/DemoClient.dll
Apr 03 09:47:04 leia democlient[3137]: info: Microsoft.Hosting.Lifetime[0]
Apr 03 09:47:04 leia democlient[3137]: Now listening on: http://localhost:5000
Apr 03 09:47:04 leia democlient[3137]: info: Microsoft.Hosting.Lifetime[0]
Apr 03 09:47:04 leia democlient[3137]: Now listening on: https://localhost:5001
Apr 03 09:47:04 leia democlient[3137]: info: Microsoft.Hosting.Lifetime[0]
Apr 03 09:47:04 leia democlient[3137]: Application started. Press Ctrl+C to shut down.
Apr 03 09:47:04 leia democlient[3137]: info: Microsoft.Hosting.Lifetime[0]
Apr 03 09:47:04 leia democlient[3137]: Hosting environment: Debug
Apr 03 09:47:04 leia democlient[3137]: info: Microsoft.Hosting.Lifetime[0]
Apr 03 09:47:04 leia democlient[3137]: Content root path: /home/berten/repositories/DemoClient/bin/Release/netcoreapp3.1/publish
当我访问时,它显示“加载…”,但不确定地挂在那里。浏览器控制台还显示styles.css和runtime-es2015.js未找到。
我的应用程序似乎可以访问,但静态文件没有正确加载/提供。我的Startup.cs中确实有这个:
app.UseStaticFiles();
if (!env.IsDevelopment())
{
app.UseSpaStaticFiles();
}
我的服务器块:
listen 443 ssl;
listen [::]:443 ssl;
include snippets/ssl-democlient.mydomain.com.conf;
index index.html index.htm index.nginx-debian.html;
server_name democlient.mydomain.com;
location / {
try_files $uri $uri/ =404;
proxy_pass https://localhost:5001;
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;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
ssl_certificate /etc/letsencrypt/live/democlient.mydomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/democlient.mydomain.com/privkey.pem; # managed by Certbot
server {
if ($host = democlient.mydomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
如果替换为,我将从democlient.mydomain.com重定向到democlient.mydomain.com:5001
我不知道该怎么做