该网站只适用于1-2个请求,之后它开始无休止地加载,如果我等待一段时间,我会得到一个内部服务器错误。在此之后,我重新加载服务器sudo systemctl reload apache 2网站为1个请求工作,我再次遇到同样的问题(当我使用runserver 0.0.0.0:8000时,它工作正常)
我在Ubuntu 22.04上使用Django应用程序
使用apache 2和libapache 2-mod-wsgi-py 3的Libapache版本是:
libapache2-mod-wsgi-py3/jammy-updates,jammy-security,now 4.9.0-1ubuntu0.1 amd64 [installed]
Python版本3.10.12
我的apache文件conf etc/apache 2/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)指定的超时已过期:[客户端82.194.20.184:60468] mod_wsgi(pid=6140):无法代理来自守护程序的响应。,referer: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,referer: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,referer:http://www.caspian-bavarians.com/az/cars/ [Fri Sep 22 05:50:33.804640 2023] [wsgi:error] [pid 6139:tid 140592298276416](70007)指定的超时已过期:[客户端82.194.20.184:63960] mod_wsgi(pid=6139):无法代理来自守护程序的响应。,referer: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,referer: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,referer: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-py 3的版本
- 尝试重新启动系统
- 禁用然后启用网站
1条答案
按热度按时间u0sqgete1#
我找到了解决办法:在apache配置文件(在我的例子中,是etc/apache 2/apache.conf)中添加这一行: