部署thin + nginx

部署thin + nginx
生成配置文件

thin config -C /etc/thin/<config-name>.yml -c <rails-app-root-path> --servers <number-of-threads> -e <environment>

thin config -C /etc/thin/myapp.yml -c /var/rails/myapp --servers 5 --socket /tmp/thin.myapp.sock -e development

替换<config-name>为自己的应用名称,替换<rails-app-root-path>为应用的根目录,替换<number-of-threads>为启动的线程数,也就是启动多少个Thin服务,替换<environment>为运行环境。
thin:
environment: development
address: 0.0.0.0
port: 3001
timeout: 30
log: log/thin.log
pid: tmp/pids/thin.pid
max_conns: 1024
max_persistent_conns: 512
wait: 30
servers: 2
daemonize: true
# require: []

启动: thin start -C config/thin.yml
停止: thin stop -C config/thin.yml

nginx:

server {
     listen 3001;
     charset utf-8;
     root /var/rails/mysapp/public;
     access_log logs/access.log;
     error_log  logs/error.log;

     location / {
         # proxy_pass          http://rails_servers;
         # proxy_redirect      default;
         proxy_redirect      false;
         proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header    X-Real-IP $remote_addr;
         proxy_set_header    Host $http_host;
         proxy_next_upstream http_502 http_504 error timeout invalid_header;
         proxy_pass false;

        if (-f $request_filename/index.html)
        {
          rewrite (.*) $1/index.html break;
        }
        if (-f $request_filename.html) {
          rewrite (.*) $1.html break;
        }
        if (!-f $request_filename) {
          proxy_pass http://rails_servers;
          break;
        }
    }
 }
 upstream rails_servers{
        server 127.0.0.1:3002;
        server 127.0.0.1:3003;
 }