2013-12-10 46 views
0

我遵循this guide,並設法使Python與Django的安裝工作完美無瑕,但它似乎讓所有本地託管的PHP站點都無法訪問,從而返回404錯誤。Django/mod_wsgi使用PHP的WAMP

的httpd.conf

LoadModule wsgi_module modules/mod_wsgi.so 

#This is placed right after the rule for <Directory "f:/WAMP/www/"> 
<Directory "f:/WAMP/www/python"> 
    Options ExecCGI 
    AddHandler wsgi-script .py 
    Order allow,deny 
    Allow from all 
</Directory> 

#This is placed at the end of the file 
<IfModule ssl_module> 
SSLRandomSeed startup builtin 
SSLRandomSeed connect builtin 
</IfModule> 

Include "f:/WAMP/alias/*" 
Include "F:/WAMP/www/python/sandbox/apache/apache_django_wsgi.conf" 

apache_django_wsgi.conf

Alias /python/images/ "F:/WAMP/www/python/sandbox/images" 
<Directory "F:/WAMP/www/python/sandbox/images"> 
Order allow,deny 
Allow from all 
</Directory> 

WSGIScriptAlias /python "F:/WAMP/www/python/sandbox/apache/django.wsgi" 

<Directory "F:/WAMP/www/python/sandbox/apache"> 
Allow from all 
</Directory> 

<VirtualHost *:80> 
DocumentRoot f:/WAMP/www/python/sandbox/ 
ServerName 127.0.0.1 
</VirtualHost> 

django.wsgi

import os, sys 

sys.path.append('F:/WAMP/www/python/sandbox') 
os.environ['DJANGO_SETTINGS_MODULE'] = 'sandbox.settings' 

import django.core.handlers.wsgi 
application = django.core.handlers.wsgi.WSGIHandler() 

PHP上當我從httpd.conf註釋掉最後一行時,它會呈現。

+0

這行'DocumentRoot f:/ WAMP/www/python/sandbox /'將把所有內容發送到該目錄。我想你需要另一個虛擬主機來運行PHP。 –

+0

我懷疑是否有辦法將該特定規則本地化爲python/django目錄?設置多個虛擬主機的效率似乎低得多。 –

+0

效率不高,這是所有Apache網站的工作方式。您需要編輯您的主機文件並創建2個名爲python.dev和php.dev的站點。然後分別爲python vhost和php vhost創建'ServerName'。 –

回答

0

您需要另一個虛擬主機,如果你要設置DocumentRoot

# This is for PHP 
<VirtualHost *:80> 
DocumentRoot f:/WAMP/www/ 
ServerName local.php.dev 
</VirtualHost> 

# This is for your Django stuff 
<VirtualHost *:80> 
DocumentRoot f:/WAMP/www/python/sandbox/ 
ServerName local.py.dev 
</VirtualHost> 

否則,因爲它是現在,所有的本地請求被髮送到蟒蛇沙箱。

請注意,您需要在本地指定多個主機。