gpt4 book ai didi

带有 nginx 设置主机头的 ASP.Net Core 不起作用

转载 作者:行者123 更新时间:2023-12-02 13:46:14 25 4
gpt4 key购买 nike

我正在尝试使用 Nginx 托管我的 ASP.Net core 应用程序。

我的nginx.conf是这样的

server {
listen 80;
server_name mydomain.com;

location / {
proxy_set_header Host $host;
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_pass http://localhost:5000;
}
}

我将此代码添加到配置方法以使用转发 header

app.UseForwardedHeaders(new ForwardedHeadersOptions {
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto,
ForwardLimit = null,
RequireHeaderSymmetry = false
});

我从浏览器导航到 mydomain.com,直到我单击“Loggin with google”(使用 google 登录)按钮,它才会起作用。它重定向到 http://localhost:5000/signin-google 而不是 http://mydomain.com/signin-google。

如何将其重定向到 http://mydomain.com/signin-google ?

最佳答案

我相信 proxy_redirect 指令会有所帮助。

根据: NGinX Documentation for proxy_redirect

proxy_redirect:“设置代理服务器响应的“位置”和“刷新” header 字段中应更改的文本。”

所以:

proxy_redirect http://localhost:5000/ http://example.com/

可能是您问题的解决方案。

您甚至可以使用变量来简化支持?

proxy_redirect http://localhost:5000/ http://$host:$server_port

进一步阅读: Host ASP.NET Core on Linux with Nginx

关于带有 nginx 设置主机头的 ASP.Net Core 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41009174/

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