I hosted a BlazorServerSide created with .NET5 on Ubuntu 20.04. When I start the app directly with dotnet command, it works fine. However, when it is started by systemd service, the static files are not loaded. The wwwroot directory and its contents do exist. By the way, I have removed the symbolic link to the default file in /etc/nginx/sites-enabled/
. Is this the cause?
nginx config:
server {
server_name {My_FQDN} www.{My_FQDN};
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;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.{My_FQDN}/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.{My_FQDN}/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = {My_FQDN}) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = www.{My_FQDN}) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name {My_FQDN}
listen 80;
return 404; # managed by Certbot
}
service file:
[Unit]
Description=MyBlazorApp.
After=local-fs.target
[Service]
Type=simple
ExecStart=/usr/bin/dotnet /home/{username}/{MY_BLAZOR_APP_DIR}/{MY_APP_NAME}.dll
RemainingAfterExit=yes
RestartSec=10
KillSignal=SIGINT
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
using Microsoft.AspNetCore.HttpOverrides;
...
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseAuthentication();
and Resolved by setting the application directory to /var/www/{AppDir}
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.