python - 在 Windows 中使用 Apache + mod_wsgi + Python Django 的 408 请求超时
问题描述
我有一个 Django 应用程序,它在 Windows 下使用 Apache + mod_wsgi 部署在本地网络中。当我跑步时python manage.py runserver
,一切正常。但是当我启动 Apache 服务时,我无法访问该应用程序。我从 access.log 得到的唯一响应是错误代码408
。下面是我的httpd.conf
:
LoadFile "c:/users/felix/appdata/local/programs/python/python37/python37.dll"
LoadModule wsgi_module "c:/users/felix/appdata/local/programs/python/python37/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "c:/users/felix/appdata/local/programs/python/python37"
ServerName localhost
WSGIScriptAlias / "D:/dev/test_server/django/django/wsgi_windows.py"
Listen 8000
<VirtualHost *:8000>
WSGIPassAuthorization On
ErrorLog "logs/django.error.log"
CustomLog "logs/django.access.log" combined
Alias /static "D:/dev/test_server/staticfiles"
<Directory "D:/dev/test_server/staticfiles">
Require all granted
</Directory>
<Directory "D:/dev/test_server/django/django">
<Files wsgi_windows.py>
Require all granted
</Files>
</Directory>
<Directory />
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
下面是wsgi_windows.py
文件:
# Activate the virtualenv
activate_this = 'D:/dev/test_server/.venv/Scripts/activate_this.py'
exec(open(activate_this).read(), dict(__file__=activate_this))
import os # noqa
import sys # noqa
import site # noqa
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('D:/dev/test_server/.venv/Lib/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('D:/dev/test_server/django')
sys.path.append('D:/dev/test_server/django/django')
os.environ['DJANGO_SETTINGS_MODULE'] = 'django.settings'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django.settings")
from django.core.wsgi import get_wsgi_application # noqa
application = get_wsgi_application()
我将不胜感激有关该问题的任何想法或提示。
解决方案
- 使用“httpd”在命令行启动 apache 并查找错误消息。如果 Apache 在启动时出现问题,则日志文件中没有消息。
- 检查 error.log 您甚至可以将 'print('xyz') 放在 settings.py 和其他地方,通过检查 error.log 来查看您的应用程序的设置方式以及请求的处理程度。如果您的应用程序像这样卡在某个地方,您会找到卡住的代码
推荐阅读
- azure - 在 Azure 管道中,如何为无头 Chrome 测试设置 X 显示?
- php - mysql数据库的PHP未定义索引错误
- python - 为什么字符串乘法的字节码不同?
- excel - 在 selenium VBA 中使用 datepicker 插入日期
- python - 如何在 Pyqt5 的 QMainWindow 中将小部件放在背景图像上?
- python - DJANGO - 如何从同一表单内的其他 Select 字段动态填充/过滤 Select 字段
- java - Android - 如何以可读的方式链接多个异步方法
- artificial-intelligence - 我的 CLIPS 代码有什么不好的 - 或/和变化或 else-if 语法?
- r - case_when 在 mutate 函数中出错:输入必须是向量
- python - 在python中将所有零移动到数组的末尾