我一直在尝试自学如何创建和部署 Django 应用程序。我创建了一个测试项目,可以使用 Django 测试服务器浏览它。现在我想使用 apache 和 mod_wsgi 来部署它。
我按照安装说明进行操作快速安装指南并安装了 mod_wsgi。然后我查看了快速配置指南并且能够成功连接到我的浏览器中的示例输出。
我现在开始讨论与 Django 的集成(http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango) 部分,我无法取得任何进展。每当我尝试浏览我为项目设置的 URL 时,我都会看到使用配置指南创建的示例的输出。我查看了 apache 错误日志,其中没有任何消息(我在调试第一个示例时收到了一些消息,所以我知道我正在查看正确的日志)。我甚至设置了“LogLevel info”以尝试在日志中获取更多详细信息,但什么也没有。
有没有人有什么建议?
这是我的apach2.conf:
LockFile ${APACHE_LOCK_DIR}/accept.lock
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
<IfModule mpm_worker_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
<IfModule mpm_event_module>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
AccessFileName .htaccess
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy all
</Files>
DefaultType text/plain
HostnameLookups Off [3]:
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
Include mods-enabled/*.load
Include mods-enabled/*.conf
Include httpd.conf
Include ports.conf
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
Include conf.d/
Include sites-enabled/
这是我的httpd.conf:
ServerName HomeServer
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
这是 VitualHost:
<VirtualHost *:80>
ServerName ppbase.homeserver
ServerAdmin [email protected]
DocumentRoot /var/projects/ppbase/ppbase
<Directory /var/projects/ppbase/ppbase>
Order allow,deny
Allow from all
</Directory>
LogLevel info
WSGIScriptAlias / /var/projects/ppbase/django.wsgi
<Directory /var/projects/ppbase>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
这是 django.wsgi:
import os
import sys
projectpath = '/var/projects/ppbase'
projectapppath = '/var/projects/ppbase/ppbase'
if projectpath not in sys.path:
sys.path.append(projectpath)
if projectapppath not in sys.path:
sys.path.append(projectapppath)
os.environ['DJANGO_SETTINGS_MODULE'] = 'ppbase.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
答案1
确保在 apache 中启用你的 vhost 文件。