python - Apache 中的 dJango mod_wsgi 配置问题

标签 python django apache timeout mod-wsgi

我正在尝试使用 Apache (2.4) 和 mod_wsgi 运行 dJango(1.5) 应用程序。我已经遵循了标准教程。我还以文件所有者(我自己)和组的身份运行 apache 用户和组。当我点击一个 url 后,它会等待很长时间,然后给出网关超时。 Apache 命中了 wsgi.py 和 upto settings.py,因为我在/var/log/apache2/error.log 中看到了 settings.py 中的所有打印语句,但之后没有输出。是不是没有获取到urls.py?有人可以帮忙吗?我在这里给出我的 httpd.conf。

WSGIDaemonProcess imse_wsgi python-path=/ldata/Imse user=www-data

<VirtualHost *:80>

    ServerName wonders.pc.hiit.fi
    ServerAlias imse.hiit.fi

    Alias /static/ /ldata/Imse/static/

    <Directory /ldata/Imse/static>
            Require all granted
    </Directory>

    WSGIScriptAlias /imse /ldata/Imse/Imse/wsgi.py
    <Directory /ldata/Imse/Imse>
            Require all granted
            WSGIProcessGroup imse_wsgi
            <Files wsgi.py>
                    Require all granted
            </Files>
    </Directory>
    <IfModule mod_headers.c>
            Header set Access-Control-Allow-Origin "*"
    </IfModule>
</VirtualHost>

这里是wsgi.py

import os
import sys
import django.core.handlers.wsgi

sys.path.append('/ldata/Imse')
sys.path.append('/ldata/Imse/Imse')

os.environ["DJANGO_SETTINGS_MODULE"] = "Imse.settings"
application = django.core.handlers.wsgi.WSGIHandler()

apache2重启时的错误日志

[Tue Oct 28 00:03:28.525134 2014] [mpm_event:notice] [pid 26381:tid 139811474503552] AH00491: caught SIGTERM, shutting down
[Tue Oct 28 00:03:29.592849 2014] [mpm_event:notice] [pid 4084:tid 139694197917568] AH00489: Apache/2.4.10 (Debian) mod_wsgi/4.3.0 Python/2.7.8 configured -- resuming normal operations
[Tue Oct 28 00:03:29.592960 2014] [core:notice] [pid 4084:tid 139694197917568] AH00094: Command line: '/usr/sbin/apache2'

当我点击网址时

[Tue Oct 28 00:05:49.754939 2014] [wsgi:error] [pid 4087:tid 139693984982784] Env loaded
[Tue Oct 28 00:05:49.755014 2014] [wsgi:error] [pid 4087:tid 139693984982784] Application loaded
[Tue Oct 28 00:05:49.755776 2014] [wsgi:error] [pid 4087:tid 139693984982784] /ldata/Imse
[Tue Oct 28 00:05:49.755863 2014] [wsgi:error] [pid 4087:tid 139693984982784] No local settings configured, using defaults
[Tue Oct 28 00:05:49.879412 2014] [wsgi:error] [pid 4087:tid 139693984982784] URL imported
[Tue Oct 28 00:05:49.879445 2014] [wsgi:error] [pid 4087:tid 139693984982784] Loading URLs

这些是来自 wsgi.py 的打印(那些已在此处删除)和来自 settings.py 的打印,程序卡在 urls.py 中,在页面加载近 5 分钟后,页面显示网关超时并添加了一行error.log如下

[Tue Oct 28 00:10:49.654957 2014] [wsgi:error] [pid 4089:tid 139693995841280] [client 2001:708:140:200:8a51:fbff:fe64:db53:51393] Timeout when reading response headers from daemon process 'imse_wsgi': /ldata/Imse/Imse/wsgi.py

最佳答案

您的应用程序在使用 python manage.py runserver 运行时是否成功返回?尝试在代码的其他部分使用更多打印语句来调试执行。例如 urls.py。

关于python - Apache 中的 dJango mod_wsgi 配置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26565426/

相关文章:

python - 正则表达式替换字符串末尾的 '...'

python - 使用 "re.findall"拆分字符串时出错

jquery - 自动完成字段未在 django-autocomplete-light 表单集中呈现

Python:使用 html 解析器提取特定数据

python - 无效的帖子 : 400 - Bad Request with Python requests

python - 总账并发(django原子操作)

python - 如何在 Django 中创建模型包

apache - 使用 apache 进行动态主机名和端口代理

amazon-web-services - Amazon EC2 如何托管我自己的内容?停留在有一个工作测试 apache 页面上

apache - 使用mod_rewrite提供网页的移动版本