【问题标题】:restapi with Nginx and uwsgi not passing headers info使用 Nginx 和 uwsgi 休息 api 不传递标头信息
【发布时间】:2021-11-18 00:39:29
【问题描述】:

我有一个烧瓶应用程序,它在端口 5000 上仅使用 uwsgi 作为服务运行良好。我正在尝试使用 Nginx 将 https 代理到后端的端口 5000。它正在访问我的应用程序,但是我的应用程序需要在标头上发送身份验证令牌,并且在通过 Nginx 代理时我没有得到它。但是,如果我将 URL 更改为端口 5000,则会传递标头。如何配置 Nginx 以将所有内容传递给应用程序?此应用执行 GET、PUSH、PUT、DELETE 操作,用户不仅会发送标头,还会发送 json 数据。

##################### NGINX CONFIG #####################
    location /customer/ {
            include uwsgi_params;
            uwsgi_pass unix:///var/www/html/cisco/cisco.sock;
    }
    

##################### UWSGI CONFIG #####################        
[uwsgi]
module = wsgi:application

master = true
processes = 5

uid=apache
gid=apache

buffer-size = 32768

http = 0.0.0.0:5000

req-logger = file:/var/log/uwsgi/cart-req.log
logger = file:/var/log/uwsgi/cart-err.log

chmod-socket = 666
vacuum = true
socket = cisco.sock

die-on-term = false

py-autoreload = 1

【问题讨论】:

    标签: python nginx flask uwsgi


    【解决方案1】:

    我假设我们正在谈论请求标头。在这种情况下,您可以在您的位置块中使用此指令 uwsgi_pass_request_headers on;:

      location /customer/ {
                include uwsgi_params;
                uwsgi_pass_request_headers on;
                uwsgi_pass unix:///var/www/html/cisco/cisco.sock;
        }
    

    但是on 是默认值,所以如果没有关闭任何其他的标头以及请求正文应该发送到您的 Python 应用程序。

    您的标题名称是什么?您是否可以使用标头名称更新您的问题,或者更好的是curl 格式的示例 HTTP 请求?

    【讨论】:

    • 这是我正在使用的 curl 命令。 api_key 标头未通过端口 5000。curl --location --request GET 'http://some.domain.com:5000/customer/' \ --header 'api_key: someKey'
    • 如果您的 Flask-Application 没有在端口 5000 NGINX 上接收到标头,则不是问题,因为请求根本不会通过 nginx。在您的问题中,您在端口5000 上说一切正常。如果请求进入端口5000,您能否检查标题是否存在。 python代码是什么?
    • 端口 5000 功能齐全。上面的 curl 命令是工作代码。这工作正常。不起作用的是通过 Nginx 将端口 80 代理到端口 5000。标头不流过。我收到了 GET 请求,但没有收到标头。
    猜你喜欢
    • 2018-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-27
    • 2021-05-11
    • 1970-01-01
    • 2016-03-08
    相关资源
    最近更新 更多