我在 apache2 服务器 django 应用程序上遇到错误无法代理来自守护进程的响应

问题描述 投票:0回答:1

该网站仅适用于 1-2 个请求,之后它开始无休止地加载,如果我等待一段时间,我会收到内部服务器错误。 之后我重新加载服务器 sudo systemctl reload apache2 website 适用于 1 个请求,我再次遇到同样的问题 (当我使用 runserver 0.0.0.0:8000 时它工作正常)

我在 Ubuntu 22.04 上使用 django 应用程序

使用 apache2 和 libapache2-mod-wsgi-py3 Libapache 版本是:

libapache2-mod-wsgi-py3/jammy-updates,jammy-security,now 4.9.0-1ubuntu0.1 amd64 [installed]

Python 版本 3.10.12

我的apache文件conf etc/apache2/apache.conf(我在这里只添加了Servername和LimitRequestFieldSize)

ServerName caspian-bavarians.com

DefaultRuntimeDir ${APACHE_RUN_DIR}

PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 5


User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf


<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
        Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined

LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent


IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf

LimitRequestFieldSize 32768

我的网站conf文件

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.

    ServerName caspian-bavarians.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

  Alias /static /home/ftpuser/caspi/static
  <Directory /home/ftpuser/caspi/static>
    Require all granted
  </Directory>

  Alias /media /home/ftpuser/caspi/media
  <Directory /home/ftpuser/caspi/media>
    Require all granted
  </Directory>
  <Directory /home/ftpuser/caspi/main>
    <Files wsgi.py>
      Require all granted
    </Files>
  </Directory>

  WSGIScriptAlias /  /home/ftpuser/caspi/main/wsgi.py
  WSGIDaemonProcess django_app python-path=/home/ftpuser/caspi/ python-home=/home/ftpuser/venv
  WSGIProcessGroup django_app
</VirtualHost>

Apache 错误日志

[Fri Sep 22 05:38:30.466675 2023] [wsgi:error] [pid 6140:tid 140592497751616] (70007)指定的超时已过期: [client 82.194.20.184:60468] mod_wsgi (pid=6140): 失败到来自守护进程的代理响应。,参考:http://www.caspian-bavarians.com/az/cars/ [Fri Sep 22 05:38:34.918090 2023] [wsgi:error] [pid 6139:tid 140592497751616] [client 82.194.20.184:57353] 从守护进程“django_app”收到的响应标头被截断或过大:/home/ftpuser/caspi /main/wsgi.py,参考:http://www.caspian-bavarians.com/az/car/mercedes-benz-e220-7/ [Fri Sep 22 05:38:34.918108 2023] [wsgi:error] [pid 6139:tid 140592480966208] [client 82.194.20.184:57024] 从守护进程“django_app”收到的响应标头被截断或过大:/home/ftpuser/caspi /main/wsgi.py,参考:http://www.caspian-bavarians.com/az/cars/ [Fri Sep 22 05:50:33.804640 2023] [wsgi:error] [pid 6139:tid 140592298276416] (70007)指定的超时已过期: [client 82.194.20.184:63960] mod_wsgi (pid=6139): 代理失败来自守护进程的响应。,参考:http://www.caspian-bavarians.com/az/cars/ [Fri Sep 22 05:50:37.371732 2023] [wsgi:error] [pid 6139:tid 140592506144320] [client 82.194.20.184:58025] 从守护进程“django_app”读取响应标头时超时:/home/ftpuser/caspi/ main/wsgi.py,参考:http://www.caspian-bavarians.com/az/car/mercedes-benz-e220-7/ [Fri Sep 22 05:50:38.194056 2023] [wsgi:error] [pid 6140:tid 140592323454528] [client 82.194.20.184:63962] 从守护进程“django_app”读取响应标头时超时:/home/ftpuser/caspi/ main/wsgi.py,参考:http://www.caspian-bavarians.com/az/car/mercedes-benz-e220-7/ [Fri Sep 22 05:50:38.742344 2023] [wsgi:error] [pid 6139:tid 140592357025344] [client 159.203.17.7:44390] 从守护进程“django_app”收到的响应标头被截断或过大:/home/ftpuser/caspi /main/wsgi.py

我的wsgi.py

"""
WSGI config for main project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main.settings')

application = get_wsgi_application()

我的应用程序的这个版本在heroku 上运行良好

  • 我尝试了 apt-get 更新和升级
  • 检查了libapache-mod-wsqi-py3的版本
  • 尝试重新启动系统
  • 禁用然后启用网站
django apache apache2 mod-wsgi ubuntu-22.04
1个回答
0
投票

我找到了解决方案:将此行添加到您的 apache 配置文件中(在我的例子中是 etc/apache2/apache.conf):

WSGIApplicationGroup %{GLOBAL}
© www.soinside.com 2019 - 2024. All rights reserved.