Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将$ssl_客户端_s_dn从nginx/uwsgi传递到flask应用程序_Python_Nginx_Flask_Uwsgi_Client Certificates - Fatal编程技术网

Python 将$ssl_客户端_s_dn从nginx/uwsgi传递到flask应用程序

Python 将$ssl_客户端_s_dn从nginx/uwsgi传递到flask应用程序,python,nginx,flask,uwsgi,client-certificates,Python,Nginx,Flask,Uwsgi,Client Certificates,我正在用uWSGI和nginx运行一个Python web服务器,基本映像为tiangolo/uWSGI nginx 如果存在客户端证书DN,我想传递它。为此,我定义了以下nginx.conf: uwsgi_read_timeout 300; ssl_certificate /app/cert.pem; ssl_certificate_key /app/key.pem; ssl_password_file /app/password.pass; ssl_client_certif

我正在用
uWSGI
nginx
运行一个Python web服务器,基本映像为
tiangolo/uWSGI nginx

如果存在客户端证书DN,我想传递它。为此,我定义了以下
nginx.conf

uwsgi_read_timeout 300;

ssl_certificate     /app/cert.pem;
ssl_certificate_key /app/key.pem;
ssl_password_file   /app/password.pass;

ssl_client_certificate  /app/client-ca.crt;
ssl_verify_client optional;
ssl_verify_depth 2;

include uwsgi_params;
uwsgi_param HTTP_X_DN $ssl_client_s_dn;
我希望我的Flask代码接收
HTTP\u X\u DN
参数,但找不到如何接收

环顾四周,我发现它应该位于
flask
request.environ
对象中,但在打印environ内容时,我没有看到任何这样的键

作为参考,
request.environ.keys()
在通过邮递员发送请求时返回以下内容:

dict_键(['QUERY_STRING'、'REQUEST_METHOD'、'CONTENT_TYPE', “内容长度”、“请求URI”、“路径信息”、“文档根”, “服务器协议”、“请求方案”、“HTTPS”、“远程地址”, “远程端口”、“服务器端口”、“服务器名称”、“HTTP内容类型”, “HTTP\u缓存控制”、“HTTP\u邮递员令牌”、“HTTP\u用户代理”, “HTTP_接受”、“HTTP_主机”、“HTTP_接受编码”, “HTTP\u内容长度”、“HTTP\u连接”、“wsgi.input”, “wsgi.file\u包装器”、“wsgi.version”、“wsgi.errors”、“wsgi.run\u once”, “wsgi.multi-thread”、“wsgi.multi-process”、“wsgi.url\u scheme”, “uwsgi.version”、“uwsgi.node”、“werkzeug.request”])


显然,这是由于docker映像所暴露的配置的限制造成的

您现在可以完全覆盖
nginx.conf
,而之前我只覆盖
app.conf

无论如何,这是一个最有效的小解决方案,请将其添加到
/app/prestart.sh

#!/usr/bin/env bash
ex -sc '%s/include uwsgi_params;/include uwsgi_params; uwsgi_param SSL_CLIENT_S_DN $ssl_client_s_dn;/g|x' /etc/nginx/conf.d/nginx.conf