资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

怎么解决supersetnginx反向代理配置遇到的小问题

怎么解决superset nginx 反向代理配置遇到的小问题,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名申请网站空间、营销软件、网站建设、岐山网站维护、网站推广。

在用 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

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联的支持。


新闻标题:怎么解决supersetnginx反向代理配置遇到的小问题
网址分享:http://cdkjz.cn/article/jsejss.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220