在成功登录后,我试图将用户重定向回我的移动应用程序。(链接回应用程序)
为此,我使用以下链接发送307
响应:exp://192.168.178.33:19000?steamId=76561198154889373
我用go编写的服务器代码如下所示:
http.Redirect(w, r, redirectUrl+"?steamId="+steamId, 307)
nginx
对运行rest的2台服务器进行反向代理负载平衡。
下面是配置:
upstream rest_api {
server 123.456.789.123:8081 fail_timeout=10s;
server 111.222.333.444:8081 fail_timeout=10s weight=5;
}
server {
listen 443 ssl ipv6only=on;
ssl_protocols SSLv2 SSLv3 TLSv1 TLSv1.1 TLSv1.2;
server_name example.com www.example.com;
ssl_certificate /etc/nginx/ssl/chain.crt;
ssl_certificate_key /etc/nginx/ssl/privkey.key;
root /usr/share/nginx/html;
location / {
index index.html index.htm;
include /etc/nginx/headers/security_headers.conf;
include /etc/nginx/headers/default_headers.conf;
}
location /hi {
index hi.html;
}
location ~* /notfound {
index not_found.html;
}
}
server {
listen 443 ssl;
ssl_protocols SSLv2 SSLv3 TLSv1 TLSv1.1 TLSv1.2;
server_name api.example.com;
ssl_certificate /etc/nginx/ssl/chain.crt;
ssl_certificate_key /etc/nginx/ssl/privkey.key;
location / {
proxy_pass https://rest_api;
include /etc/nginx/headers/security_headers.conf;
include /etc/nginx/headers/default_headers.conf;
}
}
server {
listen 80;
listen [::]:80;
server_name example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
ssl_protocols SSLv2 SSLv3 TLSv1 TLSv1.1 TLSv1.2;
server_name example.com;
ssl_certificate /etc/nginx/ssl/chain.crt;
ssl_certificate_key /etc/nginx/ssl/privkey.key;
location ~* /notfound {
root /usr/share/nginx/html/notfound;
index not_found.html;
}
}
在不使用nginx
的情况下运行api并通过111.222.333.444:8081/login
访问/login
路由时,它可以正常工作,并且可以重定向。但是,当使用nginx
作为反向代理时,我得到了以下结果(注意,浏览器窗口的标题是rest_api
,就像nginx.conf
中的upstream
:
https://i.stack.imgur.com/4tlk3.png
链接这里,因为我还没有10个代表。
如何配置我的nginx
以将307
响应传递回应用程序,而不是陷入上游声明中?
提前谢谢。
<#>编辑
在使用nginx
上游进行负载平衡时,我在登录后会得到以下响应:
https://steamcommunity.com/openid/login?....&openid.realm=https://rest_api&openid.return_to=https://rest_api/login?redirectUrl=exp://THE_ACTUAL_REDIRECT_URL&....
这不管用
但是,当我使用没有nginx
的普通IP时,这是可行的:
https://steamcommunity.com/openid/login?....&openid.realm=https://111.222.333.444:8081&openid.return_to=https://111.222.333.444:8081/login?redirectUrl=exp://THE_ACTUAL_REDIRECT_URL
因此,在我看来,运行loadbalancer/proxy
的服务器正以rest_api
的形式向世界公开。
发布于 2022-08-15 16:09:52
在默认情况下,nginx在$proxy_host
头中传递Host
(参见下面),您需要将其更改为实际的主机:
location / {
proxy_pass https://rest_api;
proxy_set_header Host $host;
// ...
}
语法:默认情况下,只有两个字段被重新定义: proxy_set_header主机$proxy_host;proxy_set_header连接关闭;-- https://nginx.org/en/docs/http/ngx_http_代理_module.html#proxy_设置_标题 在
$proxy_host
指令中指定的代理服务器的名称和端口;-- https://nginx.org/en/docs/http/ngx_http_代理_module.html#variables
https://serverfault.com/questions/1108234
复制相似问题