- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 nginx 中设置自定义 header ,并最终将其传递给运行 django 应用程序的 gunicorn 服务器。更改 nginx 配置文件后,我检查了 django 中的 request.META 字典,但我的自定义 header 丢失了。我相信 nginx 没有正确发送 header 。这是我相关的nginx配置文件内容。
server {
listen 443;
server_name www.example.com;
client_max_body_size 40M;
ssl on;
ssl_certificate /home/ubuntu/prodStuff/ssl/server.crt;
ssl_certificate_key /home/ubuntu/prodStuff/ssl/server.key;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
ssl_prefer_server_ciphers on;
access_log /home/ubuntu/logs/nginx-access.log;
error_log /home/ubuntu/logs/nginx-error.log info;
set $mobile_rewrite perform;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if ($mobile_rewrite = perform) {
proxy_set_header renderMobileWebsite "1";
}
else{
proxy_set_header renderMobileWebsite "0";
}
proxy_pass_header renderMobileWebsite;
if (!-f $request_filename) {
proxy_pass http://djangoapp_server;
break;
}
}
然后我只是打印 request.META 但没有 renderMobileWebsite header 条目。这是打印请求的输出。META
{'HTTP_COOKIE': '_gat=1; csrftoken=mGKNffeg7DjwvAsulLigzYwzni5eu;
_ga=GA1.2.1693535173.1467728753;
sessionid=ye46dsu9ff68jktbdfhdrhhdielu2np2e0g;
wcsid=61ln3H0NVEu1RDhf285Ly32sDJ04QKE2;
hblid=wVO8zgtwCPYjhGjb285Ly32sDJ4EQK0a;
_oklv=1457358771468%2C61ln3H0NVEu1RDhf285Ly32sDJ04QKE2;
_ceg.s=o3o983; _ceg.u=o3o983', 'SERVER_SOFTWARE': 'gunicorn/19.2.1',
'SCRIPT_NAME': u'', 'REQUEST_METHOD': 'POST', 'PATH_INFO': u'/product/updateSwatch/',
'HTTP_ORIGIN': 'https://www.example.com',
'SERVER_PROTOCOL': 'HTTP/1.0',
'QUERY_STRING': '',
'CONTENT_LENGTH': '107',
'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36',
'HTTP_CONNECTION': 'close', 'HTTP_REFERER': 'https://www.example.com/catalogue/hazel/',
'SERVER_NAME': '127.0.0.1',
'REMOTE_ADDR': '127.0.0.1',
'wsgi.url_scheme': 'https',
'SERVER_PORT': '8000',
'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest',
'HTTP_X_FORWARDED_PROTO': 'https',
'REMOTE_PORT': '45389',
'wsgi.input': <gunicorn.http.body.Body object at 0x7fc0117d87d0>,
'HTTP_HOST': 'www.example.com',
'wsgi.multithread': False,
'HTTP_ACCEPT': '*/*', 'wsgi.version': (1, 0),
'RAW_URI': '/product/updateSwatch/',
'wsgi.run_once': False, 'wsgi.errors': <gunicorn.http.wsgi.WSGIErrorsWrapper object at 0x7fc0117d8450>,
'wsgi.multiprocess': True, 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8',
'gunicorn.socket': <socket._socketobject object at 0x7fc011855e50>,
'HTTP_X_FORWARDED_PORT': '443',
'CONTENT_TYPE': 'application/x-www-form-urlencoded; charset=UTF-8',
'HTTP_X_FORWARDED_FOR': '115.118.144.31, 172.31.17.146',
'wsgi.file_wrapper': <class 'gunicorn.http.wsgi.FileWrapper'>,
'HTTP_ACCEPT_ENCODING': 'gzip, deflate'}
任何人都可以告诉我我在这里做错了什么。
最佳答案
主要问题是 proxy_set_header
指令在 if
block 中是不允许的。
但是,使用 map
指令可以实现相同的功能。在 http
block 中使用以下内容:
map $mobile_rewrite $render_mobile_rewrite {
default 0;
perform 1;
}
以及您现有位置 block 中的以下内容:
proxy_set_header renderMobileWebsite $render_mobile_rewrite;
参见 this document了解详情。
关于django - 在 Nginx 配置中设置自定义 header 并将其传递给 gunicorn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35845155/
我尝试了几乎所有命令来杀死 gunicorn 服务器。但没有任何效果。我怎样才能杀死这些进程并释放 80 端口 12652 ? Ss 0:00 sudo gunicorn -b
我正在使用 Apache Airflow,发现 gunicorn-error.log 的大小在 5 个月内增长了超过 50 GB。大多数日志消息都是 INFO 级别的日志,例如: [2018-05-1
我正在使用 在 Digital Ocean 上运行 django gunicorn 和 nginx . Gunicorn 用于为静态文件提供 django 和 nginx。 通过网站上传文件后,我无法
我正在使用 Django 1.8,我想用 gunicorn 运行我的应用程序。 我可以从命令行绑定(bind)到我的 IP 运行它: gunicorn myapp.wsgi:application -
我们正在使用 https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker FastAPI 并且能够使用 gunicorn 日志文件自定义我们
我在 docker 上的 centos7 上运行 Airflow 1.8,但我的网络服务器无法访问浏览器。我通过pip2.7安装了airflow。 Flower ui 显示良好,initdb 运行连接
gunicorn.service cannot open WorkingDirectory and the gunicorn executable. I think it's about per
任何想法为什么我的 gunicorn 服务器无法启动? jeffy@originaldjangster:~$ sudo /home/jeffy/django_files/django_test_ven
我已经安装了gunicorn,但是没有找到gunicorn命令: # pip3.4 install gunicorn Requirement already satisfied (use --upgr
我在有监督的ginicorn部署我的django项目。 我在virtualenv中安装了gunicorn,添加到INSTALL_APPS中。 命令./manage.py run_gunicorn -b
我成功安装了gunicorn: remote: -----> Removing .DS_Store files remote: -----> Python app detected remote: -
Systemd 和 Gunicorn 需要某种 wsgi 文件作为 ExecStart 的最后一个参数:http://docs.gunicorn.org/en/latest/deploy.html?h
我正在尝试将基本应用程序部署到 Amazon EC2使用 Django , Gunicorn , 和 Nginx .我有应用 git clone进入我的AWS Ubuntu实例并正在运行 Django
在更新为使用小型模型中的 spacy_en_core_web_lg 后,我的 fastapi 服务器内存不足。 当运行 fastapi 时,会生成 4 个 gunicorn worker,并且根据内存
我有一个基于这个的 ansible 配置虚拟机 https://github.com/jcalazan/ansible-django-stack但出于某种原因,尝试启动 Gunicorn 会出现以下错
我关注 this如何在 Ubuntu 18.04 指南中使用 Postgres、Nginx 和 Gunicorn 设置 Django。 我创建了以下文件 .socket sudo nano /etc/
我正在尝试按照此 [链接][1] 在 Digital Ocean 上部署简单的 Django 应用程序用 gunicorn 实现它的抛出错误 gunicorn.service: Failed with
这里我想问你,用python运行gunicorn uvicorn,和默认从tiangolo有什么区别? 我尝试使用 JMeter 对这些进行压力测试具有线程属性: 从这些,我得到了结果:: 从上面我尝
因此,我有一个简单的 Flask API 应用程序,它运行在运行 tornado worker 的 gunicorn 上。 gunicorn 命令行是: gunicorn -w 64 --backlo
我已经使用 Gunicorn + Nginx + Supervisor 部署了一个 Django 1.6 应用程序。一切正常,但我的 Gunicorn error.log 一直在发送错误。该文件很大,
我是一名优秀的程序员,十分优秀!