0

我的虚拟机目前正在托管一个 django (ngsdbview) 项目(带有 virtualenv 设置的 Django 1.5/gunicorn/nginx)。我没有使用默认设置文件,而是设置了 /settings/production.py (或 dev.py 等)。所以,我之前已经为机器定义了 DJANGO_SETTINGS_MODULE 变量。

现在,我将第二个 django 项目(示例)添加到同一台机器上,想知道如何配置项目特定的 DJANGO_SETTINGS_MODULE 变量?

谢谢,高塔曼

4

2 回答 2

0

You can pass each settings file to guincorn separately for each project. I'd recommend looking into supervisord to manage your guincorn processes so that you can keep one running for each project with different settings.

You can set up your config file like

[program:project1]
command=/var/www/project1/manage.py run_gunicorn --settings=project1.settings.production
directory=/var/www/project1/
environment=PATH="/var/www/project1/venv/bin"
user=www-data
autostart=true
autorestart=true

[program:project2]
command=/var/www/project2/manage.py run_gunicorn --settings=project2.settings.production
directory=/var/www/project2/
environment=PATH="/var/www/project2/venv/bin"
user=www-data
autostart=true
autorestart=true

So instead of defining it in an environment variable, you can define your settings in your supervisord config file, which will then maintain the process for each of your projects.

于 2013-10-28T23:43:58.240 回答
0

Tim Edgar 的解决方案效果很好,我更喜欢它。

同时从这里得到提示,我 export DJANGO_SETTINGS_MODULE=myproject.settings.production 在 bin/activate 脚本中添加了。这也有效。但是,添加到激活脚本可能不是最佳解决方案,因为虚拟机的每次重新创建/新部署都会消失。

于 2013-10-29T15:50:50.670 回答