开发者

Running Django in Virtualenv using Apache with Mod_Python and Multiple Python installations

I would like to run a Django project on a server using virtualenv in Apache using mod_python. Now I know that the recommended apache module to use is mod_wsgi, but I don't want to install that for now.

The default python installation on the server is python2.4, which is used by some other website on the server. Because my project was built on python2.6 I installed it next to python2.4 in /usr/local/ using 'make altinstall'. I've used this website to setup my apache conf file: http://mydjangoblog.com/2009/03/30/django-mod_python-and-virtualenv/.

My question is: is t开发者_JAVA百科here a way to specify that it (mod_python probably) should use python2.6 instead of python2.4? If there is no way to run 2 python versions in one apache using mod_python, would it be possible using mod_wsgi? Or would it be possible in one apache installation with the other site using mod_python and me using mod_wsgi?


No, you cannot do this. mod_python is pre-compiled with a particular Python version. If you wanted to change that version, you'd have to re-compile mod_python - and if you're doing that, you might as well install mod_wsgi.

It is possible with mod_wsgi, as that doesn't embed an interpreter into Apache itself, so it doesn't care what version you use. It's quite easy to get virtualenv working with mod_wsgi - you just need to activate the virtualenv inside your .wsgi script:

activate_this = os.path.join(path_to_my_site, "bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))


You could also run the django project with a runwsgiserver on a different port and then use apache with a reverse proxy.

like so:

source your_env/bin/activate
python manage.py runwsgiserver host=localhost port=8123

and the reverse proxy on apache:

<VirtualHost *:80>
    ServerName sitename.com
    ServerAlias www.sitename.com

ProxyRequests Off

<Proxy *>
Order deny,allow
Allow from all
</Proxy>

ProxyPass / http://localhost:8123/
ProxyPassReverse / http://localhost:8123/

</VirtualHost>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜