[英]Use Apache 2 + mod_wsgi for Python app
I'm trying to use Apache 2 + mod_wsgi for my Python app. 我正在尝试将Apache 2 + mod_wsgi用于我的Python应用程序。 But get an error:
但是得到一个错误:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@test.local and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
My configurations: Ubuntu 12.04, Apache2, Python3.3, Django 1.6, libapache2-mod-wsgi-py3. 我的配置:Ubuntu 12.04,Apache2,Python3.3,Django 1.6,libapache2-mod-wsgi-py3。
My settings. 我的设置。
Folder structure: 资料夹结构:
www
└── test.local
├── test_site
│ ├── manage.py
│ └── test_site
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── test_site.wsgi
/etc/hosts: / etc / hosts:
127.0.0.1 localhost
127.0.0.2 test.local
127.0.1.1 ube-home
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
/etc/apache2/sites-available/test.local /etc/apache2/sites-available/test.local
<VirtualHost 127.0.0.2:80>
ServerAdmin webmaster@test.local
ServerName test.local
ServerAlias www.test.local
WSGIScriptAlias / /home/ube/www/test.local/test_site.wsgi
DocumentRoot /home/ube/www/test.local
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/ube/www/test.local/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride ALl
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
/home/ube/www/test.local/test_site.wsgi /home/ube/www/test.local/test_site.wsgi
import os
import sys
sys.path.append('/home/ube/www/test.local/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'test_site.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I haven't forgotten: 我没有忘记:
sudo a2ensite test.local
sudo service apache2 restart
Error log says: 错误日志显示:
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] File "/home/ube/www/test.local/test_site.wsgi", line 5, in <module>
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] import django.core.handlers.wsgi
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] ImportError: No module named django.core.handlers.wsgi
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] mod_wsgi (pid=15638): Target WSGI script '/home/ube/www/test.local/test_site.wsgi' cannot be loaded as Python module.
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] mod_wsgi (pid=15638): Exception occurred processing WSGI script '/home/ube/www/test.local/test_site.wsgi'.
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] File "/home/ube/www/test.local/test_site.wsgi", line 5, in <module>
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] import django.core.handlers.wsgi
[Sun Mar 30 01:35:06 2014] [error] [client 127.0.0.1] ImportError: No module named django.core.handlers.wsgi
Solution in my case: 我的解决方案:
import os
import sys
sys.path.append('/home/ube/www/test.local/test_site/')
sys.path.append('/home/ube/www/test.local/')
sys.path.append('/home/ube/www/')
sys.path.append('/usr/local/lib/python3.3/dist-packages')
os.environ['DJANGO_SETTINGS_MODULE'] = 'test_site.settings'
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()
I added more sys.path =). 我添加了更多的sys.path =)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.