您现在的位置是:首页 > 文章详情

superset nginx 反向代理配置遇到的一个小问题

日期:2019-08-15点击:642

在用 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 http://$env; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_http_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 http://127.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: http://release/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 $http_host; 
curl -I http://127.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: http://127.0.0.1:10001/superset/welcome 

更多架构、PHP、GO相关踩坑实践技巧请关注我的公众号

原文链接:https://my.oschina.net/u/222608/blog/3093021
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章