使用Apache和mod_wsgi部署django时出错

时间:2014-06-10 15:03:16

标签: python django apache mod-wsgi

我正在尝试使用Apache和mod_wsgi为django应用程序部署django。我已经为配置提供了this,并在“使用mod_wsgi守护进程模式”进行了配置。

这是我在/etc/httpd/conf.d

中的Apache虚拟主机配置文件
<VirtualHost *:80>
ServerName test.uws.com
ErrorLog /home/visho/http_error.log
WSGIDaemonProcess visho.uws.com python-path=/home/visho/vishoweb:/home/visho/vishoweb/venv/lib/python2.6
WSGIScriptAlias / /home/visho/vishoweb/visho_website/wsgi.py
WSGIProcessGroup visho.uws.com
Alias /static /home/visho/static/
Alias /vishofiles /home/visho/
<Directory /home/visho/vishoweb/visho_website>
   <Files wsgi.py>
       Order deny,allow
       Allow from all
   </Files>
</Directory>
</VirtualHost>

请参阅此处提到的路径内容。

ls -l / home / visho / vishoweb

drwxr-xr-x 3 visho visho 4096 Jun 10 07:39 adminuser
-rw-r--r-- 1 visho visho  256 Jun 10 06:12 manage.py
-rw-r--r-- 1 visho visho   75 Jun 10 06:12 requirements.txt
drwxr-xr-x 5 visho visho 4096 Jun 10 07:23 venv
drwxr-xr-x 2 visho visho 4096 Jun 10 10:36 visho_website

ls -l /home/visho/vishoweb/venv/lib/python2.6

lrwxrwxrwx 1 visho visho    39 Jun 10 07:23 _abcoll.py -> /opt/python2.6/lib/python2.6/_abcoll.py
-rw-r--r-- 1 visho visho 24369 Jun 10 07:23 _abcoll.pyc
lrwxrwxrwx 1 visho visho    35 Jun 10 07:23 abc.py -> /opt/python2.6/lib/python2.6/abc.py
-rw-r--r-- 1 visho visho  6412 Jun 10 07:23 abc.pyc
lrwxrwxrwx 1 visho visho    38 Jun 10 07:23 codecs.py -> /opt/python2.6/lib/python2.6/codecs.py
-rw-r--r-- 1 visho visho 39635 Jun 10 07:23 codecs.pyc
lrwxrwxrwx 1 visho visho    35 Jun 10 07:23 config -> /opt/python2.6/lib/python2.6/config
lrwxrwxrwx 1 visho visho    40 Jun 10 07:23 copy_reg.py -> /opt/python2.6/lib/python2.6/copy_reg.py
-rw-r--r-- 1 visho visho  5519 Jun 10 07:23 copy_reg.pyc
drwxr-xr-x 2 visho visho  4096 Jun 10 07:23 distutils
lrwxrwxrwx 1 visho visho    38 Jun 10 07:23 encodings -> /opt/python2.6/lib/python2.6/encodings
lrwxrwxrwx 1 visho visho    39 Jun 10 07:23 fnmatch.py -> /opt/python2.6/lib/python2.6/fnmatch.py
-rw-r--r-- 1 visho visho  3765 Jun 10 07:23 fnmatch.pyc
lrwxrwxrwx 1 visho visho    43 Jun 10 07:23 genericpath.py -> /opt/python2.6/lib/python2.6/genericpath.py
-rw-r--r-- 1 visho visho  3602 Jun 10 07:23 genericpath.pyc
lrwxrwxrwx 1 visho visho    40 Jun 10 07:23 lib-dynload -> /opt/python2.6/lib/python2.6/lib-dynload
lrwxrwxrwx 1 visho visho    41 Jun 10 07:23 linecache.py -> /opt/python2.6/lib/python2.6/linecache.py
-rw-r--r-- 1 visho visho  3454 Jun 10 07:23 linecache.pyc
lrwxrwxrwx 1 visho visho    38 Jun 10 07:23 locale.py -> /opt/python2.6/lib/python2.6/locale.py
-rw-r--r-- 1 visho visho     0 Jun 10 07:23 no-global-site-packages.txt
lrwxrwxrwx 1 visho visho    38 Jun 10 07:23 ntpath.py -> /opt/python2.6/lib/python2.6/ntpath.py
-rw-r--r-- 1 visho visho    14 Jun 10 07:23 orig-prefix.txt
lrwxrwxrwx 1 visho visho    34 Jun 10 07:23 os.py -> /opt/python2.6/lib/python2.6/os.py
-rw-r--r-- 1 visho visho 28085 Jun 10 07:23 os.pyc
lrwxrwxrwx 1 visho visho    41 Jun 10 07:23 posixpath.py -> /opt/python2.6/lib/python2.6/posixpath.py
-rw-r--r-- 1 visho visho 11901 Jun 10 07:23 posixpath.pyc
lrwxrwxrwx 1 visho visho    34 Jun 10 07:23 re.py -> /opt/python2.6/lib/python2.6/re.py
-rw-r--r-- 1 visho visho 13815 Jun 10 07:23 re.pyc
drwxr-xr-x 7 visho visho  4096 Jun 10 07:23 site-packages
-rw-r--r-- 1 visho visho 27552 Jun 10 07:23 site.py
-rw-r--r-- 1 visho visho 25395 Jun 10 07:23 site.pyc
lrwxrwxrwx 1 visho visho    43 Jun 10 07:23 sre_compile.py -> /opt/python2.6/lib/python2.6/sre_compile.py
-rw-r--r-- 1 visho visho 11917 Jun 10 07:23 sre_compile.pyc
lrwxrwxrwx 1 visho visho    45 Jun 10 07:23 sre_constants.py -> /opt/python2.6/lib/python2.6/sre_constants.py
-rw-r--r-- 1 visho visho  6248 Jun 10 07:23 sre_constants.pyc
lrwxrwxrwx 1 visho visho    41 Jun 10 07:23 sre_parse.py -> /opt/python2.6/lib/python2.6/sre_parse.py
-rw-r--r-- 1 visho visho 20843 Jun 10 07:23 sre_parse.pyc
lrwxrwxrwx 1 visho visho    35 Jun 10 07:23 sre.py -> /opt/python2.6/lib/python2.6/sre.py
lrwxrwxrwx 1 visho visho    36 Jun 10 07:23 stat.py -> /opt/python2.6/lib/python2.6/stat.py
-rw-r--r-- 1 visho visho  3013 Jun 10 07:23 stat.pyc
lrwxrwxrwx 1 visho visho    37 Jun 10 07:23 types.py -> /opt/python2.6/lib/python2.6/types.py
-rw-r--r-- 1 visho visho  2806 Jun 10 07:23 types.pyc
lrwxrwxrwx 1 visho visho    40 Jun 10 07:23 UserDict.py -> /opt/python2.6/lib/python2.6/UserDict.py
-rw-r--r-- 1 visho visho 10287 Jun 10 07:23 UserDict.pyc
lrwxrwxrwx 1 visho visho    40 Jun 10 07:23 warnings.py -> /opt/python2.6/lib/python2.6/warnings.py
-rw-r--r-- 1 visho visho 13745 Jun 10 07:23 warnings.pyc

ls -l / home / visho / vishoweb / visho_website

-rw-r--r-- 1 visho visho    0 Jun 10 06:12 __init__.py
-rw-r--r-- 1 visho visho  145 Jun 10 07:39 __init__.pyc
-rw-r--r-- 1 visho visho 2599 Jun 10 07:38 settings.py
-rw-r--r-- 1 visho visho 2767 Jun 10 07:39 settings.pyc
-rw-r--r-- 1 visho visho  492 Jun 10 06:12 urls.py
-rwxr-xr-x 1 visho visho  400 Jun 10 10:36 wsgi.py

在我为checkin apache语法运行httpd -t时配置apache后,它表示一切都很好。

但是当我重新加载Apache时,我收到以下错误。请看看它,并帮助我解决这个问题,因为我是初学者,我不知道什么是错的。

这是日志

[Tue Jun 10 10:51:48 2014] [error] Traceback (most recent call last):
[Tue Jun 10 10:51:48 2014] [error]   File "/home/visho/vishoweb/visho_website/wsgi.py", line 9, in <module>
[Tue Jun 10 10:51:48 2014] [error]     import os
[Tue Jun 10 10:51:48 2014] [error] ImportError: No module named os
[Tue Jun 10 10:53:13 2014] [error] mod_wsgi (pid=7192): Unable to import 'site' module.
[Tue Jun 10 10:53:27 2014] [error] mod_wsgi (pid=7192): Unable to import 'site' module.
[Tue Jun 10 10:53:27 2014] [error] [client 14.141.33.202] mod_wsgi (pid=7192): Target WSGI script '/home/visho/vishoweb/visho_website/wsgi.py' cannot be loaded as Python module.
[Tue Jun 10 10:53:27 2014] [error] [client 14.141.33.202] mod_wsgi (pid=7192): Exception occurred processing WSGI script '/home/visho/vishoweb/visho_website/wsgi.py'.

请注意这是我的/home/visho/vishoweb/visho_website/wsgi.py内容。

WSGI config for visho_website project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "visho_website.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

2 个答案:

答案 0 :(得分:0)

与无法导入“site”或其他系统模块相关的任何问题通常是因为mod_wsgi使用了错误的Python安装。详情请见:

浏览该文件并:

验证mod_wsgi的设置方式并确定问题。

答案 1 :(得分:-2)

我唯一看不到的是虚拟主机配置中的DocumentRoot。尝试将其设置为

DocumentRoot /home/visho/vishoweb/visho_website

在vhost的Directory部分之前的某个地方