平台: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
You don’t need the django.wsgi file, point WSGIScriptAlias to mysite/wsgi.py
The way of doing uwsgi and so is completely PHP way, which is not nice enough.