Kiran Patil said almost 7 years ago on Production Deployment on Ubuntu :

Hi,


Please add nginx with puma configuration for production.


Thanks.


David Kimura PRO said almost 7 years ago on Production Deployment on Ubuntu :

This is the config that I use for nginx/puma. The puma.rb is within the rails application's config folder.

nginx.conf

upstream backend {
  server unix:///var/run/puma/my_app.sock;
}
server {
  listen 80;
  server_name _ localhost;
  access_log /var/log/nginx/access.log main;
  error_log /var/log/nginx/error.log;
  large_client_header_buffers 8 32k;
  root /var/app/current/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_set_header X-NginX-Proxy true;
    proxy_buffers 8 32k;
    proxy_buffer_size 64k;
    proxy_pass http://backend;
    proxy_redirect off;
    # enables WS support
    location /cable {
      proxy_pass http://backend;
      proxy_http_version 1.1;
      proxy_set_header Upgrade "websocket";
      proxy_set_header Connection "Upgrade";
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
  }
  
  location /assets {
    alias /var/app/current/public/assets;
    gzip_static on;
    gzip on;
    expires max;
    add_header Cache-Control public;
  }
  location /public {
    alias /var/app/current/public;
    gzip_static on;
    gzip on;
    expires max;
    add_header Cache-Control public;
  }
}

config/puma.rb

threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads 2, threads_count
port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
workers ENV.fetch("WEB_CONCURRENCY") { 2 }
preload_app!
before_fork do
  ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
end
on_worker_boot do
  ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end
plugin :tmp_restart



Kiran Patil said almost 7 years ago on Production Deployment on Ubuntu :

Thanks, one more thing is don't we need daemonize to run puma in background and environment is pointing to "development" in pumb.rb but it should be "production".


Kiran Patil said almost 7 years ago on Production Deployment on Ubuntu :
Hi, Have you used capistrano for app deployment ? Please throw some light on it. Thanks.

Kiran Patil said almost 7 years ago on Production Deployment on Ubuntu :
What would be configuration/tuning for postgresql on production ?

David Kimura PRO said almost 7 years ago on Production Deployment on Ubuntu :
I don't do too much with PostgreSQL, but is there specific cases that you're looking for?

Kiran Patil said almost 7 years ago on Production Deployment on Ubuntu :
No, I am looking for generic configuration tuning for on-premise server.

amarillo11 said over 6 years ago on Production Deployment on Ubuntu :
Any reasoning on rvm over rbenv?

David Kimura PRO said over 6 years ago on Production Deployment on Ubuntu :
it is a personal preference. Ive been using it for years without problems so I have not had a reason to change.

Login to Comment