gpt4 book ai didi

asp.net-core - "Blocked loading mixed active content"在使用 IdentityServer4 的 Blazor WebAssembly 应用程序中

转载 作者:行者123 更新时间:2023-12-03 16:48:53 37 4
gpt4 key购买 nike

我正在尝试在我的 Web 服务器上运行默认的 Blazor WebAssembly 项目模板。项目在本地运行时,没有任何问题。将其部署到服务器后出现问题。

我可以成功导航到不需要身份验证的任何页面。但是,当我尝试输入需要登录的内容时,可以看到这样的消息:

There was an error trying to log you in: 'Network Error'



enter image description here

在网络浏览器控制台中,我可以看到:

Blocked loading mixed active content “http://[subdomain.domain.com]/.well-known/openid-configuration



在 Firefox 的“网络”选项卡中,请求被标记为“已阻止”。

我的网络服务器在充当反向代理的 Nginx 上运行。我计划在 Internet 和 Nginx 之间配置 HTTPS 加密。 Nginx 和其他服务之间的通信旨在通过纯 HTTP 进行。这是我的 Nginx 配置:
server {
listen 80;

location / {
return 301 https://$host$request_uri;
}
}

[...]
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name subdomain.domain.com;

ssl_certificate /etc/nginx_ssl/live/fullchain.pem;
ssl_certificate_key /etc/nginx_ssl/live/privkey.pem;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;

location / {
proxy_pass http://blazorapp:80;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $server_name;

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

我的猜测

从浏览器错误信息中可以看出,浏览器尝试访问 .well-known/openid-configuration通过 HTTP,而不是 HTTPS。问题可能出在这里。

你有什么想法可能是错的吗?

最佳答案

我有同样的问题,也想知道正确答案,因为到目前为止我发现的似乎只是一种解决方法:
添加

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
<head> Client/wwwroot/index.html的部分和 Server/Pages/Shared/_Layout.shtml .
有了这个,应用程序显示“授权...”和“检查登录状态...”比通过 http 访问的时间长得多,但至少它可以工作。

更新
以前的解决方案确实是一个蹩脚的解决方法。我想我找到了一个更好的。
最初的问题是因为 openid-configuration 包含使用不同架构的 URL:http 而不是 https。我们可以通过在 Startup.cs 中以这种方式注册来更改 IdentityServer 使用的基本 URL:
services.AddIdentityServer(
options => {
options.PublicOrigin = Configuration.GetValue<string>("PublicOrigin");
})
当然,我们还必须在 appsettings.json 中提供正确的 URL:
{
//snip
"PublicOrigin": "https://subdomain.domain.com",
//snip
}
现在它对我来说很好用。

关于asp.net-core - "Blocked loading mixed active content"在使用 IdentityServer4 的 Blazor WebAssembly 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62005160/

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