【问题标题】:Flask - Truncated or oversized response headers received from daemon processFlask - 从守护进程收到的截断或过大的响应标头
【发布时间】:2019-03-19 16:03:04
【问题描述】:

我一直在寻找许多类似的问题,但似乎没有适合我的问题的解决方案,所以我在这里发布。

我不知道如何解决这个错误:

“从守护进程收到的截断或过大的响应标头”

我的服务器配置:

  • Apache 2.4.34 (Ubuntu)
  • mod_wsgi 4.5.17
  • OpenSSL 1.1.1
  • Python 3.6

我收到的确切错误日志是:

[Tue Mar 19 15:14:43.666649 2019] [wsgi:info] [pid 7988] mod_wsgi (pid=7988): Initializing Python.
[Tue Mar 19 15:14:43.684932 2019] [ssl:info] [pid 7945] [client X.X.X.X:X] AH01964: Connection to child 1 established (server app.com:443)
[Tue Mar 19 15:14:43.762255 2019] [wsgi:info] [pid 7988] mod_wsgi (pid=7988): Attach interpreter ''.
[Tue Mar 19 15:14:43.836994 2019] [ssl:info] [pid 7946] [client X.X.X.X:X] AH01964: Connection to child 2 established (server neuralytics.ai:443)
[Tue Mar 19 15:14:43.967857 2019] [wsgi:error] [pid 7947] [client X.X.X.X:X] Truncated or oversized response headers received from daemon process 'flaskapi': /path/to/subdomain/flaskapp.wsgi, referer: https://subdomain.app.com/register

如您所见,LogLevel 设置为 info。

flaskapp.wsgi

#!/usr/bin/python3
activate_this = '/var/subdomain/app.com/public/path/to/my/virtualenv/bin/activate_this.py'
exec(open(activate_this).read())

import sys
import logging
logging.basicConfig(stream=sys.stderr)

path = '/var/subdomain/app.com/public/path/to/flask'
if path not in sys.path:
    sys.path.append(path)

from main import app as application
application.secret_key = '****'

.conf 文件 处理多个子域。最重要的部分与 subdomain.app.com 相关:

#WSGIPythonPath /usr/bin/python3
<IfModule mod_ssl.c>
<VirtualHost *:443>
        [...]
        ServerName app.com
        ServerAlias www.app.com
        [...]
</VirtualHost>
<VirtualHost *:443>
        ServerName subdomain.app.com
        DocumentRoot /var/subdomain/app.com/public
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerAlias subdomain.app.com
Include /etc/letsencrypt/options-ssl-apache.conf
WSGIDaemonProcess flaskapi python-path=/var/subdomain/app.com/public/:/var/subdomain/app.com/public/path/to/my/virtualenv/lib/python3.6/site-packages/
WSGIProcessGroup flaskapi
WSGIScriptAlias / /var/subdomain/app.com/public/flaskapp.wsgi
WSGIApplicationGroup %{GLOBAL}
<Directory /var/subdomain/app.com/public>
        Require all granted
</Directory>
Alias /static/ /var/subdomain/app.com/public/production/static/
<Directory /var/api/neuralytics.ai/public/production/static/>
     Require all granted
</Directory>
SSLCertificateFile /etc/letsencrypt/live/app.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/app.com/privkey.pem
</VirtualHost>
</IfModule>

响应标头的 Chrome 开发输出:

HTTP/1.1 500 Internal Server Error
Date: Tue, 19 Mar 2019 15:25:58 GMT
Server: Apache/2.4.34 (Ubuntu)
Content-Length: 627
Connection: close
Content-Type: text/html; charset=iso-8859-1

请求标头的 Chrome 开发人员输出:

POST /register HTTP/1.1
Host: subdomain.app.com
Connection: keep-alive
Content-Length: 164
Origin: https://subdomain.app.com
X-CSRFToken: *******
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36
Content-Type: application/json;charset=UTF-8
Accept: */*
Referer: https://subdomain.app.com/register
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,fr;q=0.8,es;q=0.7
Cookie: session=******

你们中有人知道如何解决这个问题吗? 这也是我的第一篇 stackoverflow 帖子,所以我希望这足够详细,如果不是,请告诉我:)

【问题讨论】:

    标签: python apache mod-wsgi


    【解决方案1】:

    很抱歉回复晚了,但我遇到了同样的问题,我遵循了这个解决方案并为我工作。 https://stackoverflow.com/a/56753895/8569520

    在我的情况下,问题出在 psycopg2 版本上,我将它更新到最新版本并且它工作了

    【讨论】:

    • 我遇到了同样的问题,从 psycopg2 2.7.6.1 更新到 2.8.3 解决了这个问题。我还必须使用 sudo apt-get install libpq-dev python-dev 安装 postgres 要求。
    【解决方案2】:

    我在使用 Apache 2.4、MariaDB 10.5、mod_wsgi 4.9、Python 3.9.6、Flask 2.0.1 和 mysql-connector 2.2.9 在 Fedora 34 上通过 MySQL 查询检索数据时遇到了这个问题。
    为了解决这个问题,我必须在虚拟主机配置中设置 WSGIDaemonProcess header-buffer-size 参数。
    这个参数的默认值是32768字节,所以我增加了。
    WSGIDaemonProcess 文档:
    https://modwsgi.readthedocs.io/en/master/configuration-directives/WSGIDaemonProcess.html

    【讨论】:

    • 这实际上解决了错误消息所抱怨的问题。我正在从一个大型数据集中生成一个网页。在我将默认的 32K 翻两番到 header-buffer-size 131072 后,错误停止了。
    【解决方案3】:

    我做了所有建议的一切。没有结果。原因是mysql.connector。将其替换为 pymysql。没关系。

    【讨论】:

      猜你喜欢
      • 2014-09-09
      • 2015-06-20
      • 2017-11-08
      • 1970-01-01
      • 1970-01-01
      • 2023-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多