设置具有多个域的 Django Fast CGI 配置的推荐方法
我正在创建一个将由多个域使用的 Django 项目,并且功能会根据域的不同而略有不同。我正在寻找有关正确设置方法的建议。
这 sites 框架似乎非常适合做一些事情一旦处理达到执行 Django 代码的程度,就会进行自定义。但我试图确定在达到这一点之前应该进行哪些设置(与 nginx、flup、fastcgi、config 相关)。
这是我目前的理解:
似乎多个 Django 设置文件是合适的,每个文件都有不同的 SITE_ID。然后,将在 nginx 配置中设置两个虚拟主机,这两个虚拟主机将指向两个不同的套接字。然后,两个“manage.py runfastcgi”进程将用于侦听这两个不同的套接字,每个进程将引用不同的 settings.py
./manage.py --settings=settings.site1.py runfcgi method=prefork socket=/home/user/mysite1.sock pidfile=django1.pid
./manage.py --settings=settings.site2.py runfcgi method=prefork socket=/home/user/mysite2.sock pidfile=django2.pid
但是,如果添加更多域,这似乎可能会变得混乱。这将需要为每个要添加的域运行一个新的“管理 runfastcgi”进程。有没有一种方法可以以这种方式支持多个站点,而无需为每个站点运行单独的进程?
您使用 Django 托管多个域的经验是什么?
非常感谢任何建议。感谢您的阅读。
乔
I'm creating a Django project that will be used by multiple domains, and the functionality will be slightly different depending on the domain. I'm looking for advice on the proper way to set this up.
The
sites framework seems like it would be a good fit for doing some of the customizations once processing has reached the point where it's executing the Django code. But I'm trying to determine what the setup should be before we reach that point (relating to the nginx, flup, fastcgi, config).
Here is my current understanding:
It seems like multiple Django settings files are appropriate, each with a different SITE_ID. Then two virtual hosts would be setup in the nginx configuration that would point to two different sockets. Two 'manage.py runfastcgi' processes would then be used to listen on those two different sockets and each process would reference a different settings.py
./manage.py --settings=settings.site1.py runfcgi method=prefork socket=/home/user/mysite1.sock pidfile=django1.pid
./manage.py --settings=settings.site2.py runfcgi method=prefork socket=/home/user/mysite2.sock pidfile=django2.pid
However, it seems like this could get messy if you add more domains. It would require a new 'manage runfastcgi' process to be run for every domain that would be added. Is there a way to support multiple sites in this way without running a separate process for each?
What are your experiences with hosting multiple domains with Django?
Any advice is much appreciated. Thank you for reading.
Joe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您要运行许多域,则每个域一个进程可能会变得相当昂贵。该网站框架最初是考虑到另一个用例而设计的:能够轻松地在多个新闻网站上创建“重复”内容。当尝试将站点框架用于其他用途时,您会遇到一些困难。
一种可能性是将域处理移至中间件并让 django 处理多域部分。但这并不是一件小事,特别是如果您必须调整应用程序以使其能够识别域,以及 urlconf、模板等......快速的谷歌搜索显示:
http://djangosnippets.org/snippets/1119/
可能会有所帮助作为起点。
If you are going to have a lot of domains running, one process per domain might get quite expensive. The sites framework was originally made with another use case in mind: being able to easily create "duplicate" content on several news sites. When trying to use the sites framework for other uses you run into several difficulties.
one possibility is to move the domain processing to a middleware and have django handle the multidomain part. It's not trivial though, specially if you have to tweak apps to be domain aware, and also urlconfs, templates, etc... A quick google search showed up:
http://djangosnippets.org/snippets/1119/
Might help as a starting point.