我設置了python/flask/uwsgi + nginx web應用程序,它工作正常。我想用geoip,我把它設置在nginx端:如何閱讀從nginx傳遞的python/flask中的UWSGI參數
location/{
include uwsgi_params;
uwsgi_pass unix:/tmp/qbaka-visit.sock;
...
uwsgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
}
但是現在我不知道如何在python中讀取這個屬性。在使用uwsgi之前,我使用了簡單的內置webserver + nginx proxy_pass,在這種情況下,我使用proxy_set_header X-Geo-Country $geoip_country_code;
並使用request.headers
讀取此參數,但對於UWSGI參數,我無法弄清楚如何讀取它們。
非常感謝,這工作。 – Daniil
謝謝你。不過,我似乎無法在任何地方找到關於使用'uwsgi_param'設置HTTP標頭的*官方文檔。有人碰巧有參考嗎? – esmail
@esmail:請求頭和HTTP_之間的關係不是uwsgi的一部分,而是'wsgi' /'pep-333'(請參閱:https://www.python.org/dev/peps/pep -0333 /#ENVIRON變量)。 'uwsgi_param'在傳遞給應用程序的環境中設置鍵值對。事實上,'pep-333'特別將這些委託給cgi規範:https://tools.ietf.org/html/rfc3875#section-4.1.18 – SingleNegationElimination