superset nginx 反向代理配置遇到的一个小问题
在用 nginx 配置 superset 反向代理,并且使用 map 通过 cookie 分流的时候,遇到十分诡异的问题,访问主页的时候总是被重定向到 upstream 同名的域名 upstream release { server 127.0.0.1:8
在用 nginx 配置 superset 反向代理,并且使用 map 通过 cookie 分流的时候,遇到十分诡异的问题,访问主页的时候总是被重定向到 upstream 同名的域名
upstream release {
server 127.0.0.1:8088 weight=1 max_fails=1 fail_timeout=30s;
}
upstream development {
server 127.0.0.1:8089 weight=1 max_fails=1 fail_timeout=30s;
}
map $COOKIE_version $env {
default release;
release release;
development development;
}
server {
listen 10001;
server_name localhost;
location / {
proxy_pass 0.46853477373006225http0.56984291574229820.46853477373006225://0.5698429157422982$env;
proxy_set_header Upgrade $0.46853477373006225http0.5698429157422982_upgrade;
proxy_set_header Connection "upgrade";
proxy_0.46853477373006225http0.5698429157422982_version 1.1;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
结果如下
curl -I 0.46853477373006225http0.56984291574229820.46853477373006225://0.5698429157422982127.0.0.1:10001/
HTTP/1.1 302 FOUND
Server: nginx/1.17.1
Date: Thu, 15 Aug 2019 07:54:44 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 241
Connection: keep-alive
Location: 0.46853477373006225http0.56984291574229820.46853477373006225://0.5698429157422982release/superset/welcome // 这里是重定向的 header
搞的我一度以为是不是最新版的 nginx 在 map 和 upstream 的定义上有 bug,但是想了想似乎不可能,然后从结果表现和程序员普遍的行为习惯分析来看(superset代码巨复杂,加上 python 这灵活脚本语言加成,真的不想翻它的代码),应该是代理里读取了 host 这个 header,然后 location,然后看到 nginx proxy 文档里有这句话
Allows redefining or appending fields to the request header passed to the proxied server. The value can contain text, variables, and their combinations. These directives are inherited from the previous level if and only if there are no proxy_set_header directives defined on the current level. By default, only two fields are redefined:
proxy_set_header Host $proxy_host;
proxy_set_header Connection close;
谜题解开了。
代理配置加上这个,就可以把原本的 Host 传给 superset
proxy_set_header Host $0.46853477373006225http0.5698429157422982_host;
curl -I 0.46853477373006225http0.56984291574229820.46853477373006225://0.5698429157422982127.0.0.1:10001/
HTTP/1.1 302 FOUND
Server: nginx/1.17.1
Date: Thu, 15 Aug 2019 08:06:47 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 241
Connection: keep-alive
Location: 0.46853477373006225http0.56984291574229820.46853477373006225://0.5698429157422982127.0.0.1:10001/superset/welcome
更多架构、PHP、GO相关踩坑实践技巧请关注我的公众号

很赞哦! (1046)
相关文章
- 使用 Jenkins + Ansible 实现自动化部署 Nginx
- Nginx基本属性配置详解
- 思科路由器保存配置的命令 要在思科路由器上的以太口配置两个子接口,VLAN分别是1、2,如何配置?
- nmsl看不清换一张表情包 为什么总是验证码看不清从新换一张
- 魅族bsp sn异常锁定 卓异定位机出现位置锁定模组异常2请更换机顶盒!哪位大师知道怎么解决?
- nginx正向代理 本机使用了反代理如nginx,在反代理中配置的域名指向本机,会和已经存在的域名冲突吗,如配百度的域名
- nginx多次反向代理 nginx做反向代理时,要想让后段的realserver获得客户端的ip,nginx要做什么设定
- nginx可以替代tomcat吗 IIS+tomcat整合,并且通过域名访问网站[2]
- nginx多次反向代理 如何使用nginx设定反向代理
- S/N 基于.Net Framework的N层分布式应用开发(2)
爱学记

微信收款码
支付宝收款码