I've been trying to teach myself to create and deploy Django apps. I've created a test project and I can browse it using the Django test server. Now I want to deploy it using apache and mod_wsgi.
I followed the installation instruc开发者_JAVA技巧tions at the Quick Installation Guide and got mod_wsgi installed. I then went through the example in the Quick Configuration Guide and was able to successfully connect to the example output in my browser.
I've now moved on to the Integration With Django section and I can't make any progress with it. Any time I try to browse to the URL I've set up for my project I just see the default apache index page. I've looked at the apache error log and there are no messages in it (I got a few when I was debugging the first example so I know I'm looking at the correct log). I tried the initial example wsgi application in the django project folder, but I got the same default index page. I even set 'LogLevel info' to try and get more detail, but there was none.
Does anyone have any suggestions?
Here is my 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
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/
Here is my httpd.com:
ServerName HomeServer
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
Here is the VitualHost:
<VirtualHost *:80>
ServerName ppbase.homeserver
ServerAdmin admin@example.com
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>
And here is the 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()
If you get the "It works!" page there is nothing you can see "wrong" in the logs.
Assuming that you're working with virtual hosts, It just means that the default apache config "is a better match" than your django virtual host.
You can define a better rule for your app in the virtual host configuration or, rough and easy, disable the default apache site with (assuming you're on *NIX)
sudo a2dissite default
sudo /etc/init.d/apache2 reload
Forget it. I was being a total idiot. I'd set up my vhost file, but I hadn't enabled it in apache.
精彩评论