[英]Correct setup for multiple web sites with nginx, django and celery
Im trying to find some information on the correct way of setting up multiple django sites on a linode (Ubuntu 12.04.3 LTS (GNU/Linux 3.9.3-x86_64-linode33 x86_64) 我试图找到一些关于在linode上设置多个django站点的正确方法的信息(Ubuntu 12.04.3 LTS(GNU / Linux 3.9.3-x86_64-linode33 x86_64)
Here is what I have now: 这就是我现在拥有的:
Webserver: nginx 网络服务器:nginx
Every site is contained in a .virtualenv 每个站点都包含在.virtualenv中
Django and other packages is installed using pip in each .virtualenv 在每个.virtualenv中使用pip安装Django和其他软件包
RabbitMQ is installed using sudo apt-get rabbitmq
, and a new user and vhost is created for each site. 使用sudo apt-get rabbitmq
安装RabbitMQ,并为每个站点创建一个新用户和vhost。
Each site is started using supervisor script: 每个站点都使用supervisor脚本启动:
[group:<SITENAME>]
programs=<SITENAME>-gunicorn, <SITENAME>-celeryd, <SITENAME>-celerycam
[program:<SITENAME>-gunicorn]
directory = /home/<USER>/.virtualenvs/<SITENAME>/<PROJECT>/
command=/home/<USER>/.virtualenvs/<SITENAME>/bin/gunicorn <PROJECT>.wsgi:application -c /home/<USER>/.virtualenvs/<SITENAME>/<PROJECT>/server_conf/<SITENAME>-gunicorn.py
user=<USER>
autostart = true
autorestart = true
stderr_events_enabled = true
redirect_stderr = true
logfile_maxbytes=5MB
[program:<SITENAME>-celeryd]
directory=/home/<USER>/.virtualenvs/<SITENAME>/<PROJECT>/
command=/home/<USER>/.virtualenvs/<SITENAME>/bin/python /home/<USER>/.virtualenvs/<SITENAME>/<PROJECT>/manage.py celery worker -E -n <SITENAME> --broker=amqp://<SITENAME>:<SITENAME>@localhost:5672//<SITENAME> --loglevel=ERROR
environment=HOME='/home/<USER>/.virtualenvs/<SITENAME>/<PROJECT>/',DJANGO_SETTINGS_MODULE='<PROJECT>.settings.staging'
user=<USER>
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 600
[program:<SITENAME>-celerycam]
directory=/home/<USER>/.virtualenvs/<SITENAME>/<PROJECT>/
command=/home/<USER>/.virtualenvs/<SITENAME>/bin/python /home/<USER>/.virtualenvs/<SITENAME>/<PROJECT>/manage.py celerycam
environment=HOME='/home/<USER>/.virtualenvs/<SITENAME>/<PROJECT>/',DJANGO_SETTINGS_MODULE='<PROJECT>.settings.staging'
user=<USER>
autostart=true
autorestart=true
startsecs=10
Question 1: Is this the correct way? 问题1:这是正确的方法吗? Or is it a better way to do this? 或者这是一个更好的方法吗?
Question 2: I have tried to install celery flower , but how does that work with multiple sites? 问题2:我曾尝试安装芹菜花 ,但这对多个网站有何影响? Do I need to install one flower-package for each .virtualenv, or could I use one install for every site? 我是否需要为每个.virtualenv安装一个花包,或者我可以为每个站点使用一个安装吗? How do I setup nginx to display the flower-page(s) on my server? 如何设置nginx以在我的服务器上显示花页?
There are - as so often :) - several ways to go. 有 - 经常这样:) - 几种方法去。 We do set it up in a similar way. 我们以类似的方式进行设置。
For the supervisor configuration I would suggest to use a little bit less verbose way, below an example for running web/tasks for 'example.com': 对于supervisor配置,我建议使用一些不那么冗长的方式,下面是为'example.com'运行web / tasks的示例:
/etc/supervisor/conf.d/example.com.conf /etc/supervisor/conf.d/example.com.conf
(we usually have the config files in the repository as well, and just symlink them. So this file could be a symlink to: (我们通常在存储库中也有配置文件,只需对它们进行符号链接。所以这个文件可以是一个符号链接:
/var/www/example.com/conf/supervisord.conf ) /var/www/example.com/conf/supervisord.conf )
[group:example.com]
programs=web, worker, cam
[program:web]
command=/srv/example.com/bin/gunicorn project.wsgi -c /var/www/example.com/app/gunicorn.conf.py
directory=/var/www/example.com/app/
user=<USER>
autostart=true
autorestart=true
redirect_stderr=True
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=5
stdout_logfile=/var/log/apps/web.example.com.log
[program:worker]
command=/srv/example.com/bin/celery -A project worker -l info
directory=/var/www/example.com/app/
user=<USER>
autostart=true
autorestart=true
redirect_stderr=True
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=5
stdout_logfile=/var/log/apps/web.example.com.log
[program:flower]
command=/srv/example.com/bin/celery flower -A project --broker=amqp://guest:guest@localhost:5672//example.com/ --url_prefix=flower --port 5001
directory=/var/www/example.com/app/
...
So you have less to type and it is easier to read.. 因此您输入的内容更少,更容易阅读..
# restart all 'programs'
supervisorctl restart example.com:*
# restart web/django
supervisorctl restart example.com:web
etc.
Not totally sure if it is the best way, but what I would do here (and usually do): 不完全确定它是否是最好的方式,但我会在这里做什么(通常做):
/etc/nginx/sites-enabled/example.conf /etc/nginx/sites-enabled/example.conf
server {
...
location /flower {
proxy_pass http://127.0.0.1:5001;
...
Access the flower interface at example.com/flower 访问example.com/flower上的flower界面
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.