Debian/Ubuntu + NginX + uWSGI + Django 1.3.1 + Python 2.7.2

Install Python

$ apt-get install zlibc zlib1g-dev libxml2 libxml2-dev libbz2-dev curl build-essential python
$ curl -kL http://github.com/utahta/pythonbrew/raw/master/pythonbrew-install | bash
$ echo 'source ~/.pythonbrew/etc/bashrc' >> ~/.bashrc
$ pythonbrew install --force --no-test 2.7.2
$ pythonbrew switch 2.7.2

Install Django, uWSGI

$ pip install django psycopg2 uwsgi

Create Project

$ mkdir -p /opt/project
$ cd /opt/project
$ django-admin.py startproject sample_project
$ cd sample_project
$ mkdir media

/opt/project/sample_project 에 django0.ini를 만든다.

[uwsgi]
socket = 127.0.0.1:8000
chdir = /opt/project/sample_project
pythonpath = /opt/project
env = DJANGO_SETTINGS_MODULE=sample_project.settings
module = django.core.handlers.wsgi:WSGIHandler()
master = true
processes = 4
daemonize = /opt/project/sample_project/uwsgi0.log
pidfile = /opt/project/sample_project/uwsgi0.pid

/opt/project/sample_project 에 django1.ini를 만든다.

[uwsgi]
socket = 127.0.0.1:8001
chdir = /opt/project/sample_project
pythonpath = /opt/project
env = DJANGO_SETTINGS_MODULE=sample_project.settings
module = django.core.handlers.wsgi:WSGIHandler()
master = true
processes = 4
daemonize = /opt/project/sample_project/uwsgi1.log
pidfile = /opt/project/sample_project/uwsgi1.pid

uwsgi 실행

$ uwsgi django0.ini
$ uwsgi django1.ini

Install NginX

$ aptitude install nginx

Configure NginX

$ cd /etc/nginx/sites-available
$ vi django
upstream sample_project {
    ip_hash;
    server 127.0.0.1:8000;
    server 127.0.0.1:8001;
}

server {
    listen 80;
    server_name mydomain.com;
    
    location /site_media  {
        root /opt/project/sample_project/media/;
    }

    location / {
        include uwsgi_params;
        uwsgi_pass sample_project;
    }
}
$ cd /etc/nginx/sites-enabled
$ ln -s /etc/nginx/sites-available/django django

Run NginX

$ /etc/init.d/nginx restart

댓글

이 블로그의 인기 게시물

야마하 디지털 피아노 YDP-140

테이블위로 마우스 커서 이동시 색깔 변경하기

피아노 연습