rails + unicorn + nginx

nginx の設定

以下は自分で作成する必要のあるファイル(ubuntuの場合この位置)

$ vim /etc/nginx/sites-available/hoge
upstream application-unicorn {
    # Unicornのソケットを指定:
    server unix:/tmp/unicorn_tagrid.sock fail_timeout=0;
}

server {
・・・ 省略 ・・・
        # rails
        location / {

               # auth_basic            "Local Security Test";
               # auth_basic_user_file  "/var/www/html/hoge_project/.htpasswd";

                try_files $uri $uri/index.html  @unicorn;
        }

        # deny
        location ~ /\. {
                deny  all;
        }

        # unicorn
        location @unicorn {
                proxy_set_header X-Real-IP  $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                # 上の定義名
                proxy_pass http://application-unicorn;
        }
}

チューニング

設定ファイル

$ vim /etc/nginx/nginx.conf
# cpu数
worker_processes      4;
# ファイルオープン数を増やす
worker_rlimit_nofile  10240;

events {
    # 同時接続数を増やす
    worker_connections  10240;
}