tata色々な備忘録

データ解析、画像解析、化学分析などなど

Vagrant+VirtualBox環境の構築6(CentOS)

nginx + gunicorn + Djangoで

基本ここの通り
http://source.hatenadiary.jp/entry/2013/06/11/132346

gunicornのインストール

$ sudo easy_install gunicorn 

nginxのインストール

$ sudo yum install nginx

ログファイル用のフォルダ作成

$ sudo mkdir /etc/logs

nginx.conf ファイルを編集

$ sudo vi /etc/nginx/nginx.conf

nginx.conf

user  nginx;
worker_processes  1;
error_log  logs/error.log;
pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;

        server_name  localhost;

        location / {
            proxy_pass http://127.0.0.1:8000;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

djangoのsettings.py設定に追記

$ sudo vi settings.py
#INSTALLED_APPSの以下の行を追加
'gunicorn',

CentOSのファイアウォールを切る

$ sudo service iptables stop

djangoをgunicornで実行

$ python2.7 manage.py run_gunicorn 192.168.33.10:8000

http://192.168.33.10:8000
404画面
http://192.168.33.10:8000/admin
管理画面