平台:Centos5 ECS上的
django版本1.6
apache版本2.2
透過mod_wsgi將django專案配置到apache上一直沒有成功,單獨測試wsgi可以訪問,django單獨跑runserver也可以跑通
專案路徑:
/var/www/html
`-- mysite
|-- manage.py
|-- mysite
| |-- __init__.py
| |-- __init__.pyc
| |-- media
| |-- settings.py
| |-- settings.pyc
| |-- static
| |-- urls.py
| |-- wsgi.py
| `-- wsgi.pyc
`-- wsgi
`-- django.wsgi
透過startproject創建的項目,單獨runserver可以跑通,新增了wsgi資料夾以及django.wsgi設定檔
httpd.conf檔案中新增了:
LoadModule wsgi_module modules/mod_wsgi.so
<VirtualHost *:80>
ServerAdmin root@localhost
DocumentRoot /var/www/html
ServerName 121.40.202.235
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
WSGIScriptAlias / /var/www/html/mysite/wsgi/django.wsgi
<Directory /var/www/html/mysite>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
django.wsgi檔:
import os
import sys
import django.core.handlers.wsgi
os.environ['DJANGO_SETTINGS_MODULE']= 'mysite.settings'
sys.path.append('/usr/local/lib/python2.7/site/packages')
app_path = os.path.dirname(__file__)
if app_path not in sys.path:
sys.path.append(app_path)
application =django.core.handlers.wsgi.WSGIHandler()
重啟apache伺服器沒有問題,存取網址後報錯日誌為:
[Fri Oct 17 21:19:18 2014] [error] [client 117.89.63.242] mod_wsgi (pid=18776): Target WSGI script '/var/www/html/mysite/wsgi/django.wsgi' cannot be loaded as Python module.
[Fri Oct 17 21:19:18 2014] [error] [client 117.89.63.242] mod_wsgi (pid=18776): Exception occurred processing WSGI script '/var/www/html/mysite/wsgi/django.wsgi'.
[Fri Oct 17 21:19:18 2014] [error] [client 117.89.63.242] Traceback (most recent call last):
[Fri Oct 17 21:19:18 2014] [error] [client 117.89.63.242] File "/var/www/html/mysite/wsgi/django.wsgi", line 3, in ?
[Fri Oct 17 21:19:18 2014] [error] [client 117.89.63.242] import django.core.handlers.wsgi
[Fri Oct 17 21:19:18 2014] [error] [client 117.89.63.242] ImportError: No module named django.core.handlers.wsgi