溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么解決superset nginx 反向代理配置遇到的小問題

發(fā)布時間:2021-10-20 15:31:22 來源:億速云 閱讀:648 作者:柒染 欄目:大數(shù)據(jù)

怎么解決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;
    }
}

結(jié)果如下

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,但是想了想似乎不可能,然后從結(jié)果表現(xiàn)和程序員普遍的行為習慣分析來看(superset代碼巨復(fù)雜,加上 python 這靈活腳本語言加成,真的不想翻它的代碼),應(yīng)該是代理里讀取了 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

看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進一步的了解或閱讀更多相關(guān)文章,請關(guān)注億速云行業(yè)資訊頻道,感謝您對億速云的支持。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI