2012-04-08 60 views
0

我認爲我的apache2服務器已接近設置,但它仍然返回500錯誤。這裏是我的.wsgi文件:Django EC2的mod_wsgi配置與Apache不工作

import os, sys 

#path to directory of the .wsgi file ('apache/') 
wsgi_dir = os.path.abspath(os.path.dirname(__file__)) 

#path to project root directory (parent of 'apache/') 
project_dir = os.path.dirname(wsgi_dir) 

sys.path.append(project_dir) 
project_settings = os.path.join(project_dir, 'settings') 
os.environ['DJANGO_SETTINGS_MODULE'] = 'ecomstore.settings' 
import django.core.handlers.wsgi 
application = django.core.handlers.wsgi.WSGIHandler() 

這裏是我的virtualhost文件:

NameVirtualHost *:80 
<VirtualHost *:80> 
     ServerAdmin [email protected] 
     ServerName www.site.com 
     ServerAlias site.com 

     Alias /static /home/ecomstore/static 

     DocumentRoot /home/ecomstore 
     WSGIScriptAlias//home/ecomstore/apache/ecomstore.wsgi 

     ErrorLog /var/log/apache2/error.log 

     LogLevel warn 

     CustomLog /var/log/apache2/access.log combined 

</VirtualHost> 

這裏是我的服務器重啓:

sudo /etc/init.d/apache2 restart 
* Restarting web server apache2 
[Sun Apr 08 02:47:31 2012] [warn] module wsgi_module is already loaded, skipping 
... waiting ..........[Sun Apr 08 02:47:42 2012] [warn] module wsgi_module is already loaded, skipping 
    ...done. 

然而,即使我與國防部 - 沒有錯誤wsgi配置重啓,我仍然遇到前面提到的500內部服務器錯誤。有什麼我失蹤?

回答

0

您需要從提出請求時開始查看Apache錯誤日誌,而不是在重新啓動時查看。

問題的一個來源是sys.path不包含項目目錄的父目錄,因爲您設置了DJANGO_SETTINGS_MODULE,所以這將是必需的。去閱讀有關此要求:

http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

,並修復它。

除此之外,您需要確定它是否是Apache 500頁面或Django頁面。如果它是Django的,那麼在Django設置文件中打開DEBUG並重新啓動Apache,以便在瀏覽器中顯示完整的錯誤。解決問題後關閉DEBUG。

+0

是的,我檢查了日誌,發現這:'ImportError:無法導入設置'ecomstore.settings'(它是否在sys.path?是否有語法錯誤?):沒有模塊名爲ecomstore.settings ' – locoboy 2012-04-08 09:19:51

+0

固定上面的問題通過添加'sys.path.append('/ home')' – locoboy 2012-04-08 10:29:05

+1

順便說一句,建議將DocumentRoot設置爲你所擁有的。如果您稍後填入Apache配置,則所有源代碼都可以下載,包括Django設置文件中的數據庫密碼。切勿將DocumentRoot設置爲包含您不希望用戶能夠看到的敏感內容的位置。 – 2012-04-08 22:46:09