Я пытаюсь обслуживать проект. NET Core 3.1 Angular с виртуального сервера в DigitalOcean.
Сначала я настраиваю Nginx блок сервера для своего поддомена democlient.mydomain. com и создал простой html файл в / var / www/democlient.mydomain.com.. Затем я включил SSL, используя certbot Letsencrypt. Когда я go до https://democlient.mydomain.com, я вижу содержимое моего html файла.
Затем я создал новый проект, используя шаблон. NET Core 3.1 Angular на моем Windows 10 P C.
dotnet new angular -o DemoClient
Он выполняется локально на Windows 10. Я git клонировал его на свой компьютер с Ubuntu 18.04 в DigitalOcean и сделал символическую c ссылку на папку bin / Release / netcoreapp3.1 / publi sh в / var / www/democlient.mydomain.com.. построил приложение, используя
dotnet publish --configuration Release
и создал службу systemd
[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
Когда я посещаю https://democlient.mydomain.com показывает «Загрузка ...», но висит там неопределенно долго. В консоли браузера также указаны стили. css и runtime-es2015. js не найдены. Кажется, мое приложение доступно, но файлы c не загружены / не обслуживаются должным образом. У меня есть это в моем 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
Если я заменю https://localhost: 5001 на http://localhost: 5000 , я перенаправлен с democlient.mydomain.com на democlient.mydomain.com:5001.
Понятия не имею, как мне поступить.