Posts

Showing posts with the label supervisor

Flask + Gunicorn + Supervisor + Nginx

This morning, I deployed a Flask application in a Ubuntu 13.04 server with Nginx and Gunicorn. Here is the configuration: 0. My app code base (blog): /projects/blog/ 1. I created a shell script to run gunicorn: /projects/blog/blogguni.sh ======================== #!/bin/bash NUM_WORKERS=4 # user/group to run as ADDRESS=127.0.0.1:5000 cd /projects/blog /projects/.venv/blog/bin/gunicorn blog:app -w $NUM_WORKERS -b $ADDRESS 2. Supervisor configuration: /etc/supervisor/conf.d/blogguni.conf ========================== [program:blogguni] directory = /projects/blog/flaskr/ user = dangtrinhnt command = /projects/blog/blogguni.sh stdout_logfile = /projects/logs/supervisor_blog.log stderr_logfile = /projects/logs/supervisor_blog_error.log 3. Nginx configuration: /etc/nginx/sites-available/blog ==================== upstream blog {     server localhost:5000 fail_timeout=0; } server {     listen 80;     server_name dangtrinhnt.kd.io;     access_log /project

Supervisor - Update config

Image
After I changed the supervisor config file of an app, I restarted it, nothing change. I figure out that the "restart" does not make configuration changes available. There are 2 way to update configuration changes: 1. Restart the supervisor service: $ sudo service supervisor restart 2. Use the "update" parameter of supervisor. It will restart the applications which configuration has changed: $ sudo supervisorctl update Reference: http://www.onurguzel.com/supervisord-restarting-and-reloading/

Django & Nginx - 2 projects, 2 domains, 1 machine

Image
Assuming I have 2 Django projects which are running on port 8000 (project1) and port 8080 (project2) in a same machine. I want to make those 2 projects publicly accessible via 2 different domains: my.firstdomain.com --> project1 my.seconddomain.com --> project2 and not via 2 different ports: my.domain.com --> project1 my.domain.com:8080 --> project2 The solution is to create another server block in the nginx for the second project: 1. Edit the nginx config file /etc/nginx/site-available/default : upstream project1 {     server localhost:8000 fail_timeout=0; } upstream project2 {     server localhost:8080 fail_timeout=0; } server {     listen 80;     server_name my.firstdomain.com;     access_log /home/projects/logs/access_prj1.log;     error_log /home/projects/logs/error_prj1.log;     location /site_media/ {         alias /home/projects/project1/site_media/;     }     location / {         proxy_pass http://project1;     } } server {     listen 80;     server_

Django + Gunicorn + Nginx + Supervisor

Here is an example to run and control a web application in a production server: 1. Django : our web development platform -  https://www.djangoproject.com/ I have a django project located at ' /home/projects/my_project/ ' 2. Gunicorn : the Python WSGI HTTP server, I use it to run our web application -  http://gunicorn.org/ I will create a bash shell to run the gunicorn server at port 8000 inside the my_env virtual environment, named gunicorn.sh , place it inside the root dir of my django project ( /home/projects/my_project/gunicorn.sh ):