gpt4 book ai didi

asp.net-core - 无法在 NGINX 代理后面的 Blazor 服务器上加载静态文件

转载 作者:行者123 更新时间:2023-12-05 06:07:52 25 4
gpt4 key购买 nike

我在 Ubuntu 20.04 上托管了一个使用 .NET5 创建的 BlazorServerSide。当我直接使用 dotnet 命令启动应用程序时,它工作正常。但是,当它由 systemd 服务启动时,不会加载静态文件。wwwroot 目录及其内容确实存在。顺便说一下,我已经删除了 /etc/nginx/sites-enabled/ 中默认文件的符号链接(symbolic link)。是这个原因吗?

nginx 配置:

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
}

服务文件:

[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();

和通过将应用程序目录设置为 /var/www/{AppDir} 解决。

关于asp.net-core - 无法在 NGINX 代理后面的 Blazor 服务器上加载静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65303075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com