Configurar un servidor con thin y nginx
Instalar thin
sudo gem install thin
Configurar thin en el sistema
sudo thin install
Configurar thin en nginx
sudo thin config -C /etc/thin/<config-name>.yml -c <rails-app-root-path> --servers <number-of-threads> -e <environment> --socket /tmp/thin.sock
Reemplaza config-name con el nombre del archivo de configuracion, rails-app-root-path con la ruta de tu aplicacion rails, number-of-threads con el numero de procesos de thin que quieres iniciar y environment con el enviroment que quieres inicializar, por ejemplo
$ sudo thin config -C /etc/thin/chebyte.com.ar.yml -c /var/rails/chebyte --servers 5 -e production --socket /tmp/thin.sock
Esto nos generara el siguiente archivo en /etc/thin
--- pid: tmp/pids/thin.pid socket: /tmp/thin.sock log: log/thin.log timeout: 30 max_conns: 1024 chdir: /var/ror/chebyte max_persistent_conns: 512 environment: production servers: 4 daemonize: true require: []
Iniciamos thin
/etc/init.d/thin start
–socket /tmp/thin.sock esta opcion permite que nginx se comunique con thin mediante socket y no mediante una interace ethernet interna, muy recomendado para obtener mas perfomance
Configurar thin en nginx
user nginx; worker_processes 5; error_log /var/log/nginx.error.log; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] $request ' '"$status" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx.access.log main; sendfile on; keepalive_timeout 65; upstream thin_cluster { server unix:/tmp/thin.0.sock; server unix:/tmp/thin.1.sock; server unix:/tmp/thin.2.sock; server unix:/tmp/thin.3.sock; server unix:/tmp/thin.4.sock; } server { listen 80; server_name www.myserver.com; root /var/rails/mysapp/public; location / { 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_redirect 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://thin_cluster; break; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }



