Skip to content

Instantly share code, notes, and snippets.

@tbaba
Created April 8, 2012 13:28
Show Gist options
  • Save tbaba/2337316 to your computer and use it in GitHub Desktop.
Save tbaba/2337316 to your computer and use it in GitHub Desktop.
Nginx and Unicorn
require 'rack'
class Hello
def call(env)
[200, {'Content-Type' => 'text/plain'}, ['Hello, Nginx!']]
end
end
run Hello.new
# 2012/04/08時点のStable版は1.0.14らしいです
$ wget http://nginx.org/download/nginx-1.0.14.tar.gz
$ tar zxvf nginx-1.0.14.tar.gz
$ cd nginx-1.0.14
# モジュール的なもの(例えばgzipとかsslとか)はconfigureの段階で書いておかないと、再度コンパイルし直すことになるので注意!
$ ./configure --with-http_gzip_static_module --with-http_ssl_module
$ make
$ sudo make install
# デフォルトのprefixだとnginxは /usr/local/nginx にインストールされるようです
$ /usr/local/nginx/sbin/nginx
# コンフィグを再読み込みしたいときはreloadする
$ /usr/local/nginx/sbin/nginx -s reload
# 停止させたいときはstop
$ /usr/local/nginx/sbin/nginx -s stop
$ cd /path/to/your/app
$ unicorn -c unicorn.conf
# ここで -D オプションをつけるとデーモン起動させることも可能です。ログを見たかったらそのまんま起動して、別のターミナルで作業しましょう。
listen '/tmp/unicorn.sock'
worker_processes 4
upstream unicorntest {
server "unix:/tmp/unicorn.sock";
}
server {
listen 80;
server_name localhost;
location ~ / {
proxy_pass http://unicorntest;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment