[英]Deploy django using apache, mod-wsgi
I'm trying to deploy django
using wsgi
. 我正在尝试使用wsgi
部署django
。 But its not working. 但是它不起作用。 Will you please help me ? 你能帮我吗? thank you 谢谢
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!
UPDATE :Strange /etc/apache2/sites-enable/me
更新:奇怪的/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
Can I disable mod-python? 我可以禁用mod-python吗?
It should be obvious that your error message is coming from a different file than the one you have shown here - me
rather than default
. 很明显,您的错误消息来自与此处显示的文件不同的文件- me
而不是default
。 That file apparently has a reference to PythonHandler
, which is a directive that belongs to mod_python
which you don't seem to have installed (and shouldn't, as it is deprecated). 该文件显然引用了PythonHandler
,这是属于mod_python
的指令,您似乎尚未安装(并且不应该安装,因为已弃用)。
When you've fixed that error - most likely by removing that file altogether - you'll have another one to fix in your wsgi
file - you've added the project
path to the pythonpath, but then referenced your settings as project.settings
, so it won't be found. 修复该错误(很可能是通过完全删除该文件)后,您将在wsgi
文件中修复另一个错误-您已将project
路径添加到pythonpath中,但随后将您的设置引用为project.settings
,因此不会被找到。 Either add the parent path instead, or reference settings as just settings
. 要么添加父路径,要么将设置引用为settings
。
I'm not an expert at this stuff, but here is comparing to what I've got working. 我不是这方面的专家,但是这里与我的工作进行了比较。 I'm using mod_wsgi instead of mod_python. 我使用的是mod_wsgi而不是mod_python。 What you have in "/etc/apache2/sites-enabled/me" I seem to have sepecified in my "django.wsgi.py" file, and I have no such files under sites-enabled. 您在“ / etc / apache2 / sites-enabled / me”中拥有的内容似乎已经在我的“ django.wsgi.py”文件中进行了分隔,并且在启用了Sites的情况下没有此类文件。
To your django.wsgi.py you might need to add the path to your external libraries, and when I set the path for my project, my settings file is /var/myproject/src/myapp/settings.py, and I set the path to '/var/myproject/src', and the django_settings_module to myapp.settings. 在您的django.wsgi.py中,您可能需要将路径添加到外部库,并且当我设置项目的路径时,我的设置文件是/var/myproject/src/myapp/settings.py,然后将'/ var / myproject / src'的路径,以及django_settings_module到myapp.settings的路径。 Here's what my myproject.wsgi file looks like: 这是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()
Here is what I've got for my wsgi.conf: 这是我为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>
The /etc/apache2/sites-enable/me
file is for modpython. /etc/apache2/sites-enable/me
文件用于modpython。
You're using mod_wsgi. 您正在使用mod_wsgi。
Therefore. 因此。 Remove the /etc/apache2/sites-enable/me
and follow the documentation provided here 删除/etc/apache2/sites-enable/me
并遵循此处提供的文档
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/ https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.