簡體   English   中英

Flask - 從守護進程收到的截斷或過大的響應頭

[英]Flask - Truncated or oversized response headers received from daemon process

我一直在查看許多類似的問題,但似乎沒有解決方案適合我的問題,所以我在這里發布。

我不知道如何解決錯誤:

“從守護進程收到的響應頭被截斷或過大”

我的服務器配置:

  • Apache 2.4.34 (Ubuntu)
  • mod_wsgi 4.5.17
  • OpenSSL 1.1.1
  • 蟒蛇 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 Dev 輸出:

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 Dev 輸出:

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 帖子,所以我希望這足夠詳細,如果不是,請告訴我:)

抱歉回復晚了,但我遇到了同樣的問題,我遵循了這個解決方案並為我工作。 https://stackoverflow.com/a/56753895/8569520

在我的情況下,問題出在 psycopg2 版本上,我將其更新到最新版本並且它工作正常

在使用 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

我做了所有建議的事情。 沒有結果。 原因是mysql.connector。 用pymysql替換它。 沒關系。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM