简体   繁体   English

Django的多个站点

[英]Multiple sites with Django

Let's imagine I have two sites foo.com and bar.com. 让我们想象一下,我有两个网站foo.com和bar.com。 They both are on the same server and now running separate Django instances and apache to serve it. 它们都在同一台服务器上,现在运行单独的Django实例和apache来提供服务。 Of course each Django instance eats the memory. 当然每个Django实例都会占用内存。

While mainly those sites are the same systems, but with different apps loaded - maybe it is possible somehow to have for example one Django instance running and have multiple sites using it? 虽然主要是那些网站是相同的系统,但加载了不同的应用程序 - 也许有可能以某种方式运行一个Django实例运行并有多个网站使用它? Then I will save memory for the one instance in a particular example. 然后我将在特定示例中为一个实例节省内存。

It is possible to have different sites with their url.py files, loaded apps and so on? 有可能有不同的网站与他们的url.py文件,加载的应用程序等? And if this is the right way to go? 如果这是正确的方法?

Any tips, ideas are welcome. 欢迎任何提示,想法。

Thanks, Ignas 谢谢,伊格纳斯

Yes it is definitely possible to have different sites with different urls.py and shared apps. 是的,绝对可以让不同的网站使用不同的urls.py和共享应用。 I had to share a backend data between multiple sites. 我不得不在多个站点之间共享后端数据。 I just created 2 wsgi config files. 我刚刚创建了2个wsgi配置文件。 And 2 settings files. 还有2个设置文件。 The sites are very smiliar and didn't warrant two seperate projects. 这些网站非常熟悉,并不保证两个单独的项目。 This allows me to use one django project and backend between multiple sites. 这允许我在多个站点之间使用一个django项目和后端。 I don't quite know if this is what you were asking though... 我不太清楚这是不是你问的问题......

My own research today on the same topic leads me to the conclusion that you'll most likely have to have only one settings.py per Django instance/process. 我今天对同一主题进行的研究使我得出的结论是,你很可能每个Django实例/进程只需要一个settings.py. And the sticking point there is only one MEDIA_URL and one MEDIA_ROOT, which means all your projects media will have to be in the same location. 而且只有一个MEDIA_URL和一个MEDIA_ROOT,这意味着您的所有项目媒体必须位于同一位置。 And actually Django 1.3 has a new static file process that just goes through all the media of your seperate apps and puts them in one spot because for some reason it demands that. 实际上Django 1.3有一个新的静态文件进程,它只是通过你的单独应用程序的所有媒体,并将它们放在一个位置,因为由于某种原因它需要。 If you're using earlier versions I guess you can do it by hand. 如果您使用的是早期版本,我猜您可以手动完成。

https://docs.djangoproject.com/en/dev/howto/static-files/ https://docs.djangoproject.com/en/dev/howto/static-files/

uWSGI can serve more applications from one instance. uWSGI可以从一个实例提供更多应用程序。

See "Two Pinax site in two virtualenv in two virtualhost with only one uWSGI instance" in uWSGI examples and VirtualHosting Mode . 请参阅uWSGI 示例VirtualHosting模式中的 “在两个虚拟主机中只有一个uWSGI实例的两个虚拟环境中的两个Pinax站点”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM