许多Django应用程序在同一台服务器上

时间:2013-11-22 15:58:29

标签: python django

目前我在使用Virtualmin的服务器上使用uWSGI运行我的Django网站,因为我也需要DNS,邮件等服务器......所以每次我需要发布一个Django网站时,我都要为这个应用程序创建一个INI文件,编写nginx规则,最后重新启动我的uWSGI皇帝.....

所以我想知道是否有人知道以其他方式更容易,更快地完成这项工作。

由于

2 个答案:

答案 0 :(得分:1)

使用PuppetChef。这些将允许您完成您提到的所有事情以及更多。

答案 1 :(得分:1)

假设每个Django项目都有一个应用程序,我通常会做类似

的事情
www.mysite.com/app1
www.mysite.com/app2
www.mysite.com/app3

或使用子域名

www.mysite.com -> main application
app2.mysite.com
app3.mysite.com

这也假设你有一个virtualenv设置并且文件夹site包含你的源代码,你的应用程序文件在site/app内。

在Apache服务器配置的sites-enabled文件夹中轻松创建VirtualHost

<VirtualHost *:80>
    ServerAdmin webmaster@example.com
    ServerName  www.mysite.com
    ServerAlias mysite.com

    Alias /static/ /path/to/virtualenv/site/app/static/

    <Directory /path/to/virtualenv/site/app/static>
      Order deny,allow
      Allow from all
    </Directory>

    <Directory /path/to/virtualenv/site/ >
        Order deny,allow
        Allow from all
    </Directory>

    WSGIScriptAlias / /path/to/virtualenv/site/django.wsgi
    WSGIDaemonProcess  mysite.com user=www-data group=www-data threads=2
    WSGIProcessGroup mysite.com

     ErrorLog  /var/log/apache2/mysite.com.error.log
     CustomLog /var/log/apache2/mysite.com.access.log combined
</VirtualHost>

您需要在WSGIScriptAlias指定的路径以及加载的Apache mod_wsgi上安装Python WSGI脚本。

就个人而言,我发现配置子域比我列出的第一组URL更容易。