IdentityServer4 中的发现文档在 Ubuntu nginx 上返回 404



将我们的身份服务器部署到子路由为/identity 的 VPS 后,发现文档不再加载并始终返回 404 错误。在没有nginx的情况下运行服务器时,发现文档加载正常。

我们尝试使用以下nginx配置:

启动.cs

var identityServer = services.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;
options.PublicOrigin = "[Public facing URL]";
})
app.Map("/identity", authApp =>
{
app.UseStaticFiles("/identity");
app.UsePathBase("/identity");
authApp.UsePathBase(new PathString("/identity"));
authApp.UseIdentityServer();
app.UseMvcWithDefaultRoute();
});

location /identity {
root /var/www/identityserver/wwwroot;
proxy_pass         https://[path]:5021;
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;
}

上述配置应导致加载发现文档。但是,我们总是收到 404 未找到错误。我们是否缺少nginx或我们的身份服务器代码中的其他配置?

自从我发布这个问题以来已经有一段时间了。从那时起,对我有用的解决方案是删除

app.Map("/identity", authApp =>
{
app.UseStaticFiles("/identity");
app.UsePathBase("/identity");
authApp.UsePathBase(new PathString("/identity"));
authApp.UseIdentityServer();
app.UseMvcWithDefaultRoute();
});

我们将上面的代码替换为

authApp.UseIdentityServer();
app.UseMvcWithDefaultRoute();

上传更改后,我们将nginx配置更改为

server {
root /var/www/[location];
index index.php index.html index.htm;
server_name [SERVER_NAME];    

location / {
proxy_pass         https://127.0.0.1:[PORT];
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;
}
}

我们所做的最后一个更改是对nginx.conf文件。我们添加了以下内容来克服登录 oidc 502 错误的网关问题。

##
# signin-oidc 502 bad gateway
##
proxy_buffer_size   128k;
proxy_buffers   4 256k;
proxy_busy_buffers_size   256k;
large_client_header_buffers 4 16k;

一旦我们进行了所有这些更改,一切从那里开始一切正常。我希望这对其他人有所帮助。

最新更新