我正在尝试部署我的第一个简单的 django 网站。我有一个 VPS,装有 Ubuntu 14.07 Server、Apache 2.4.7 和 mod_wsgi。
因此,我添加了这个 vhost:
<VirtualHost *:80>
ServerName api.XXX.net
ServerAdmin [email protected]
DocumentRoot /var/www/XXX.net/api
WSGIScriptAlias / /var/www/XXX.net/api/backgrounds-apps-server/XXX/index.wsgi
WSGIDaemonProcess api.XXX.net processes=2 threads=15 python-path=/var/www/XXX.net/api:/var/www/XXX.net/api/lib/python3.4/site-packages
WSGIProcessGroup api.XXX.net
<Directory /var/www/XXX.net/api/backgrounds-apps-server>
Order allow,deny
Allow from all
</Directory>
Alias /static/ /var/www/XXX.net/api/backgrounds-apps-server/XXX/static/
<Location "/static/">
Options -Indexes
</Location>
LogLevel info
ErrorLog ${APACHE_LOG_DIR}/api_XXX_error.log
CustomLog ${APACHE_LOG_DIR}/api_XXX_access.log combined
</VirtualHost>
和我的index.wsgi:
import os, sys, site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/var/www/XXX.net/api/lib/python3.4/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('/var/www/XXX.net/api/backgrounds-apps-server')
sys.path.append('/var/www/XXX.net/api/backgrounds-apps-server/movies_wallpaper')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "movies_wallpaper.settings")
#Activate your virtual environment
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
但是当我尝试加载页面时,出现了 500 错误。在 apache 日志中我们可以看到以下内容:
[Mon Oct 06 16:27:42.625220 2014] [:info] [pid 3050] mod_wsgi (pid=3050): Adding '/var/www/XXX.net/api' to path.
[Mon Oct 06 16:27:42.625433 2014] [:info] [pid 3050] mod_wsgi (pid=3050): Adding '/var/www/XXX.net/api/lib/python3.4/site-packages' to path.
[Mon Oct 06 16:27:42.626344 2014] [:info] [pid 3050] [remote 188.121.29.164:61055] mod_wsgi (pid=3050, process='api.XXX.net', application='api.XXX.net|'): Loading WSGI script '/var/www/XXX.net/api/backgrounds-apps-server/movies_wallpaper/index.wsgi'.
[Mon Oct 06 14:27:43.418048 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] mod_wsgi (pid=3050): Target WSGI script '/var/www/XXX.net/api/backgrounds-apps-server/movies_wallpaper/index.wsgi' cannot be loaded as Python module.
[Mon Oct 06 14:27:43.418082 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] mod_wsgi (pid=3050): Exception occurred processing WSGI script '/var/www/XXX.net/api/backgrounds-apps-server/movies_wallpaper/index.wsgi'.
[Mon Oct 06 14:27:43.418106 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] Traceback (most recent call last):
[Mon Oct 06 14:27:43.418128 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] File "/var/www/XXX.net/api/backgrounds-apps-server/movies_wallpaper/index.wsgi", line 14, in <module>
[Mon Oct 06 14:27:43.418189 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] application = get_wsgi_application()
[Mon Oct 06 14:27:43.418201 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] File "/var/www/XXX.net/api/lib/python3.4/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Mon Oct 06 14:27:43.418243 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] django.setup()
[Mon Oct 06 14:27:43.418254 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] File "/var/www/XXX.net/api/lib/python3.4/site-packages/django/__init__.py", line 21, in setup
[Mon Oct 06 14:27:43.418295 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] apps.populate(settings.INSTALLED_APPS)
[Mon Oct 06 14:27:43.418307 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] File "/var/www/XXX.net/api/lib/python3.4/site-packages/django/apps/registry.py", line 108, in populate
[Mon Oct 06 14:27:43.418444 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] app_config.import_models(all_models)
[Mon Oct 06 14:27:43.418457 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] File "/var/www/XXX.net/api/lib/python3.4/site-packages/django/apps/config.py", line 197, in import_models
[Mon Oct 06 14:27:43.418552 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] self.models_module = import_module(models_module_name)
[Mon Oct 06 14:27:43.418564 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Mon Oct 06 14:27:43.418611 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] __import__(name)
[Mon Oct 06 14:27:43.418621 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] File "/var/www/XXX.net/api/backgrounds-apps-server/movies_wallpaper/movies/models.py", line 6, in <module>
[Mon Oct 06 14:27:43.418682 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] from easy_thumbnails.fields import ThumbnailerImageField
[Mon Oct 06 14:27:43.418694 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] File "/var/www/XXX.net/api/lib/python3.4/site-packages/easy_thumbnails/fields.py", line 2, in <module>
[Mon Oct 06 14:27:43.418759 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] from easy_thumbnails import files
[Mon Oct 06 14:27:43.418783 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] File "/var/www/XXX.net/api/lib/python3.4/site-packages/easy_thumbnails/files.py", line 14, in <module>
[Mon Oct 06 14:27:43.419070 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] from easy_thumbnails import engine, exceptions, models, utils, signals, storage
[Mon Oct 06 14:27:43.419086 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] File "/var/www/XXX.net/api/lib/python3.4/site-packages/easy_thumbnails/engine.py", line 10, in <module>
[Mon Oct 06 14:27:43.419155 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] import Image
[Mon Oct 06 14:27:43.419176 2014] [:error] [pid 3050] [remote 188.121.29.164:61055] ImportError: No module named Image
Pillow 安装在虚拟环境(pyvenv-3.4)中,空闲状态下 python3.4 运行良好。
有人能告诉我我的配置有什么问题吗?
答案1
我自己解决了这个问题 - 我只是安装了错误的模块。之后I installed libapache2-mod-wsgi-py3
它就起作用了 ;)