单个域上的django的多个实例 [英] multiple instances of django on a single domain

查看:100
本文介绍了单个域上的django的多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种很好的方式,在同一个服务器上使用单个域名安装多个完全不同的Django项目。关键是我想浏览一下如下:



http ://192.168.0.1/gallery/ #a Django照片库项目

http: //192.168.0.1/blog/ #一个博客项目



这样,我可以在同一台服务器上开发和测试多个django项目只是引用不同的URL。 (注意:我不认为这个Django Sites模块是我正在寻找的,因为这些项目需要有所区别)。作为一个例子,PHP的行为是这样的,因为我可以在同一个服务器上安装像php-gallery和phpmyadmin这样的东西,只需使用不同的URL路径。有没有人知道如何使用Apache(使用mod_python或mod_wsgi)在单个服务器上在多个URL下设置多个Django项目的好资源?我想知道的事情是如何设置apache.conf,可能的virtualenv设置以及urls.py的更改以适应这一点。我看到的大部分Django部署示例都是针对每个域或子域的一个应用程序。

任何建议都不胜感激。



谢谢,BR >
Joe

解决方案

我一直处于无法使用子域的情况下,以及处理方式这与Django实际上相当简单。



几乎所有设置文件中的一切都将像一个常规的Django应用程序,除了确保这些设置包括您的项目路径:

  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对于防止同一个域上的所有应用程序重写至关重要彼此饼干。



上述说明应该涵盖Django方面,但在Web服务器端还有更多的工作要做。例如,如果您使用apache + mod_wsgi,则需要确保每个项目都有自己的wsgi脚本,如下所示:

  WSGIScriptAlias / gallery /path/to/gallery/apache/gallery.wsgi 
别名/ gallery / media / path / to / gallery / media
别名/ gallery / admin_media / path / to / gallery /venv/lib/python2.6/site-packages/django/contrib/admin/media

等。


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/ # a Django photo gallery project
http://192.168.0.1/blog/ # a blogging project

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.

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

解决方案

I've been in situations where I couldn't use subdomains, and the way to handle this with Django is pretty simple actually.

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/'

The SESSION_COOKIE_PATH is critical to prevent all your apps on the same domain from rewriting each others cookies.

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

etc.

这篇关于单个域上的django的多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆