我正在尝试使用django
部署wsgi
。但它不起作用。你能帮帮我吗?谢谢
django.wsgi.py
#!/usr/bin/python
import os, sys
sys.path.append('/home/me/project')
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
/etc/apache2/sites-available/default
<VirtualHost *:80>
ServerName www.me.org
ServerAlias *me.org
Alias /admin_media /usr/lib/python2.4/site-packages/django/contrib/admin/media
<Location /admin_media>
Order allow,deny
Allow from all
</Location>
Alias /media /var/www/media/
<Location /media>
Order allow,deny
Allow from all
</Location>
WSGIScriptAlias / /home/me/project/apache/django.wsgi
WSGIDaemonProcess me processes=2 maximum-requests=500 threads=1
WSGIProcessGroup me
</VirtualHost>
Error Message
/etc/init.d/apache2 restart
Syntax error on line 3 of /etc/apache2/sites-enabled/me:
Invalid command 'PythonHandler', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.
...fail!
更新:奇怪的/etc/apache2/sites-enable/me
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
PythonDebug On
PythonPath "['/home/me2'] + sys.path"
SetEnv DJANGO_SETTINGS_MODULE me.settings
我可以禁用mod-python吗?
答案 0 :(得分:3)
很明显,您的错误消息来自与此处显示的文件不同的文件 - me
而不是default
。该文件显然引用了PythonHandler
,这是一个属于mod_python
的指令,您似乎没有安装(并且不应该,因为它已被弃用)。
当你修复了这个错误 - 最有可能完全删除该文件 - 你还需要另一个修复你的wsgi
文件 - 你已经将project
路径添加到了pythonpath ,但随后将您的设置引用为project.settings
,因此无法找到它。请改为添加父路径,或将参考设置仅设为settings
。
答案 1 :(得分:1)
我不是这方面的专家,但这里与我的工作相比。我正在使用mod_wsgi而不是mod_python。您在“/ etc / apache2 / sites-enabled / me”中拥有的内容我似乎在我的“django.wsgi.py”文件中已经指定了,并且在启用网站的情况下我没有这样的文件。
您的django.wsgi.py可能需要添加外部库的路径,当我为项目设置路径时,我的设置文件是/var/myproject/src/myapp/settings.py,以及我将路径设置为'/ var / myproject / src',将django_settings_module设置为myapp.settings。这是我的myproject.wsgi文件的样子:
#!/usr/bin/python
import os
import sys
sys.path.append('')
sys.path.append('/usr/local/lib/python2.7/site-packages')
sys.path.append('/usr/local/lib/python2.7/site-packages/Django-1.3-py2.7.egg')
... other external libs ..
sys.path.append('/var/myproject/myapp/src')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
以下是我为wsgi.conf提供的内容:
<VirtualHost *:80>
ServerAdmin me@me.com
DocumentRoot "/var/myproject/"
ServerName localhost
ErrorLog "/var/myproject/logs/apache-error.log"
CustomLog "/var/myproject/logs/apache-access.log" common
Options ExecCGI FollowSymLinks MultiViews
AddHandler wsgi-script .wsgi
WSGIDaemonProcess asgportal
WSGIProcessGroup asgportal
Alias /static /var/myproject/media/static
WSGIScriptAlias / /var/myproject/myproject.wsgi # my django.wsgi.py file
DirectoryIndex index.html index.cgi
AddHandler cgi-script .cgi .pl
</VirtualHost>
答案 2 :(得分:1)
/etc/apache2/sites-enable/me
文件用于modpython。
你正在使用mod_wsgi。
因此。删除/etc/apache2/sites-enable/me
并按照此处提供的文档
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/