使用 Nginx 和 uwsgi 的 rest api 不传递 headers 信息
restapi with Nginx and uwsgi not passing headers info
我有一个 flask 应用程序,它在端口 5000 上仅使用 uwsgi 作为服务运行良好。我正在尝试使用 Nginx 将 https 代理到后端的端口 5000。它击中了我的应用程序,但我的应用程序需要在 header 上发送身份验证令牌,而在通过 Nginx 代理时我没有得到它。但是,如果我将 URL 更改为端口 5000,则会传递 header。如何配置 Nginx 以将所有内容传递给应用程序?此应用执行 GET、PUSH、PUT、DELETE,用户将不仅发送 header,还会发送 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
我假设我们正在谈论请求 headers。在这种情况下,您可以在 location-block:
中使用此指令 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
是默认值,因此如果没有关闭,header 和 request-body 应该被发送到您的 Python 应用程序。
你的 header 名字是什么?您是否可以使用 header 名称或更好的 curl
格式的示例 HTTP 请求来更新您的问题?
我有一个 flask 应用程序,它在端口 5000 上仅使用 uwsgi 作为服务运行良好。我正在尝试使用 Nginx 将 https 代理到后端的端口 5000。它击中了我的应用程序,但我的应用程序需要在 header 上发送身份验证令牌,而在通过 Nginx 代理时我没有得到它。但是,如果我将 URL 更改为端口 5000,则会传递 header。如何配置 Nginx 以将所有内容传递给应用程序?此应用执行 GET、PUSH、PUT、DELETE,用户将不仅发送 header,还会发送 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
我假设我们正在谈论请求 headers。在这种情况下,您可以在 location-block:
中使用此指令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
是默认值,因此如果没有关闭,header 和 request-body 应该被发送到您的 Python 应用程序。
你的 header 名字是什么?您是否可以使用 header 名称或更好的 curl
格式的示例 HTTP 请求来更新您的问题?