在一个域的Django的多个实例 [英] multiple instances of django on a single domain
问题描述
我在寻找到仅使用单个域名在同一台服务器上安装多个完全不同的Django项目的好方法。问题的关键是,我想要浏览的是这样的:
I'm looking for a good way to install multiple completely different Django projects on the same server using only a single domain name. The point is that I want to browse to something like:
http://192.168.0.1/gallery/ #一个Django照相馆项目
http://192.168.0.1/blog/ #一个博客项目
http://192.168.0.1/gallery/ # a Django photo gallery project
http://192.168.0.1/blog/ # a blogging project
这样的话,我可以开发并通过单指不同的URL测试在同一台服务器上的多个Django的项目。 (注:我不认为这Django的网站模块是我期待的,因为项目需要是不同的)。作为一个例子,PHP样的行为以这种方式,我可以安装类似PHP-画廊和phpmyadmin的同一台服务器上,只需用不同的URL路径。
This way, I can develop and test multiple django projects on the same server by just referring to different URLs. (note: I don't think this Django Sites module is what I am looking for because the projects need to be distinct). As an example, PHP kind of behaves in this way as I can install something like php-gallery and phpmyadmin on the same server, just with different URL paths.
有谁知道什么好的资源,如何设置使用Apache一台服务器(带有mod_python的或mod_wsgi的)下多个网址多个Django的项目?东西我会想知道是如何设置的apache.conf,可能的virtualenv设置和更改urls.py,以适应这一点。大多数Django的部署例子,我看到的是每域或子域一个应用程序。结果
任何意见是多少AP preciated。
Does anyone know of any good resources of how to setup multiple Django projects under multiple URLs on a single server using Apache (with either mod_python or mod_wsgi)? Things I'd be interested in knowing is how to setup the apache.conf, possible virtualenv setup, and changes to the urls.py to accommodate this. Most of the Django deployment examples that I see are for one application per domain or subdomain.
Any advice is much appreciated.
谢谢,
乔
Thanks,
Joe
推荐答案
我一直在情况下我不能使用子域名,并使用Django来处理这个问题的方法是pretty其实很简单。
I've been in situations where I couldn't use subdomains, and the way to handle this with Django is pretty simple actually.
pretty在你的设置文件要一切都会就像一个普通的Django应用程序,以确保除外这些设置包括你的项目路径:
Pretty much everything in your settings file will be just like a regular Django app, with the exception of making sure these settings include your project path:
MEDIA_URL = 'http://192.168.0.1/gallery/media/'
ADMIN_MEDIA_PREFIX = '/gallery/admin_media/'
SESSION_COOKIE_PATH = '/gallery'
LOGIN_REDIRECT_URL = '/gallery/'
LOGIN_URL = '/gallery/accounts/login/'
LOGOUT_URL = '/gallery/accounts/logout/'
该SESSION_COOKIE_PATH是prevent所有在同一个域的应用程序的关键从此改写彼此的饼干。
The SESSION_COOKIE_PATH is critical to prevent all your apps on the same domain from rewriting each others cookies.
上面的指令应包括Django的一面,但还有更多的工作要做在Web服务器端。例如,如果你使用Apache + mod_wsgi的,你需要确保每个项目都有一个被加载这样自己的WSGI脚本:
The above instructions should cover the Django side, but there's still more work to do on the web server side. For example, if you use apache+mod_wsgi you'll need to make sure each project has their own wsgi script that is loaded like this:
WSGIScriptAlias /gallery /path/to/gallery/apache/gallery.wsgi
Alias /gallery/media /path/to/gallery/media
Alias /gallery/admin_media /path/to/gallery/venv/lib/python2.6/site-packages/django/contrib/admin/media
等。
这篇关于在一个域的Django的多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!