2012-10-28 168 views
0

我已閱讀this。所以,我安裝了mod_wsgi,virtualenv(virtualenv ENV)。 (Django的1.4,Ubuntu的服務器)Django。 Apache和mod_wsgi的問題

的/ etc/apache2的/網站可用/ mysite的

<VirtualHost *:80> 
ServerName www.example.com 
ServerAlias example.com 
WSGIDaemonProcess example.com python-path=/home/user/cars/cars:/home/user/cars/ENV/lib/python2.7/site-packege 
WSGIScriptAlias//home/user/cars/cars/wsgi.py 
<Directory /home/user/cars/cars> 
<Files wsgi.py> 
Order deny,allow 
Allow from all 
</Files> 
</Directory> 
</VirtualHost> 
WSGIPythonPath /home/user/cars/ENV/lib/python2.7/site-packeges 

內部服務器錯誤

/無功/日誌/的Apache2 /error.log:

mod_wsgi (pid=3012): Exception occurred processing WSGI script '/home/user/cars/cars/wsgi.py'. 
Traceback (most recent call last): 
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 219, in __call__ 
self.load_middleware() 
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 39, in load_middleware 
for middleware_path in settings.MIDDLEWARE_CLASSES: 
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 184, in inner 
self._setup() 
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setup 
self._wrapped = Settings(settings_module) 
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 95, in __init__ 
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e)) 
ImportError: Could not import settings 'cars.settings' (Is it on sys.path?): No module named cars.settings 

請幫助我,我從來沒有用mod_wsgi配置Django。它我的第一個項目

更新

Alias /favicon.ico /home/user/cars/files/static_content/favicon.ico 
AliasMatch ^/([^/]*\.css) /home/user/cars/files/static_content/css/$1 
Alias /static/ /home/user/cars/files/static_content/ 
<Directory /home/user/cars/files/static_content> 
Order deny,allow 
Allow from all 
</Directory> 
+0

請張貼您的wsgi.py.顯然你的項目不在sys.path上。 –

+0

順便說一下,它是一個不好的剪切和粘貼,或者你真的有包python路徑和WSGIPythonPath拼寫錯誤? –

回答

1

你缺少WSGIProcessGroup指令,因此不被使用的WSGIDaemonProcess和Python的路徑選擇。在WSGIPythonPath中設置的路徑(僅適用於嵌入模式)正在使用,並且您尚未設置項目的位置。即使對於WSGIDaemonProcess的python路徑,你也有路徑錯誤。

嘗試:

<VirtualHost *:80> 
ServerName www.example.com 
ServerAlias example.com 
WSGIDaemonProcess example.com python-path=/home/user/cars:/home/user/cars/ENV/lib/python2.7/site-packages 
WSGIProcessGroup example.com 
WSGIScriptAlias//home/user/cars/cars/wsgi.py 
<Directory /home/user/cars/cars> 
<Files wsgi.py> 
Order deny,allow 
Allow from all 
</Files> 
</Directory> 
</VirtualHost> 

注意到變化到Python路徑和另外WSGIProcessGroup的。

+0

是的,它的工作:)但我有一個更多的自由度:在汽車中我有dir'文件'和subdir'static_content'。我使用'python manage.py collectstatic'並將所有靜態文件收集到該目錄中。在虛擬主機中,我有:(我更新我的第一篇文章)。但它不起作用(404爲CSS和IMG文件)。如何解決它? – tim

+0

如果你已經達到了靜態文件的預期URL,Apache在錯誤日誌文件中說了些什麼。 –