Django -带有Apache虚拟主机的中间件或子域的子域?

时间:2022-09-01 22:04:40

I'm new to Django...

我新Django……

I need to start a project that will have subdomains, but I'm little confused about this subject...

我需要启动一个有子域的项目,但我对这个主题有点困惑……

I will have a website serving Spain, other serving United Kingdom and other serving United States and I will use only one domain and 3 subdomains, just like this:

我将有一个服务于西班牙的网站,其他服务于英国和其他服务于美国的网站,我将只使用一个域和三个子域,就像这样:

Main domain:

主要领域:

mysite.com

Subdomains:

子域:

es.mysite.com
uk.mysite.com
us.mysite.com

These 3 different site in future could have to scale, each one in one dedicated server, but for now these 3 websites will use the same server.

这3个不同的网站在未来可能不得不扩展,每个都在一个专用服务器上,但现在这3个网站将使用相同的服务器。

In a previous question I was told to use a middleware solution(http://thingsilearned.com/2009/01/05/using-subdomains-in-django/) but I don't konw if it this that I need. With this solution if I need to scale the websites for dedicated servers each one I think will not work...

在前面的一个问题中,我被告知要使用一个中间件解决方案(http://thingsilearned.com/2009/01/05/using-subdomains-indjango/),但是我不知道我是否需要这个解决方案。有了这个解决方案,如果我需要扩展专用服务器的网站,我认为每一个都行不通……

It is possible to define instead the subdomains in Apache Virtual Hosts? What do you think of using 3 different Django projects with Apache Virtual Hosts will doing the job? This is a better solution or I should go with middleware?

可以在Apache虚拟主机中定义子域吗?您认为使用3个不同的Django项目和Apache虚拟主机可以完成这个任务吗?这是一个更好的解决方案,还是我应该使用中间件?

Best Regards,

最好的问候,

1 个解决方案

#1


2  

If you're looking to expand the subdomains to different servers eventually, the easier solution will probably be using virtual hosts on your web server.

如果您希望最终将子域扩展到不同的服务器,那么更简单的解决方案可能是在web服务器上使用虚拟主机。

Each host can just use a separate settings module (they can all import * from a common settings module, changing any database / language settings which are specific to that domain).

每个主机都可以使用单独的设置模块(它们都可以从公共设置模块导入*,更改特定于该域的任何数据库/语言设置)。

Deploying this way means you have a higher memory usage, since you will be dealing with separate instances for each domain, but that doesn't sound like it will be a problem for you and your long term direction. It also makes things simpler, using middleware can get messy (especially with tests and the like).

以这种方式部署意味着您有更高的内存使用,因为您将处理每个域的单独实例,但是这听起来并不会对您和您的长期方向造成问题。它还使事情变得更简单,使用中间件可能会很麻烦(特别是对于测试之类的)。

#1


2  

If you're looking to expand the subdomains to different servers eventually, the easier solution will probably be using virtual hosts on your web server.

如果您希望最终将子域扩展到不同的服务器,那么更简单的解决方案可能是在web服务器上使用虚拟主机。

Each host can just use a separate settings module (they can all import * from a common settings module, changing any database / language settings which are specific to that domain).

每个主机都可以使用单独的设置模块(它们都可以从公共设置模块导入*,更改特定于该域的任何数据库/语言设置)。

Deploying this way means you have a higher memory usage, since you will be dealing with separate instances for each domain, but that doesn't sound like it will be a problem for you and your long term direction. It also makes things simpler, using middleware can get messy (especially with tests and the like).

以这种方式部署意味着您有更高的内存使用,因为您将处理每个域的单独实例,但是这听起来并不会对您和您的长期方向造成问题。它还使事情变得更简单,使用中间件可能会很麻烦(特别是对于测试之类的)。