Setup nginx and puma for Rails apps on Ubuntu

November 8, 2014

Continue from previous post Setup Ruby on Rails, PostgreSQL and Redis on Ubuntu, in this post I will share with you how I set up nginx and puma to deploy my Rails application on Ubuntu server.



sudo apt-get update
sudo apt-get install nginx


Disable default site by removing the symlink in folder /etc/nginx/site-enabled:

sudo rm /etc/nginx/site-enabled/default

Now let’s create your new virtual host config file /etc/nginx/sites-available/ for your Rails app:

I have used the unix socket unix:///tmp/app_name.sock to bind it with puma later. If you use ssl for your host, you can use this configuration

Next, we enable this configuration by creating a symlink in /etc/nginx/site-enabled

sudo ln -sf /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Then restart nginx server to apply these changes:

sudo service nginx restart



Add gem 'puma' to the Gemfile of your Rails application.


Start your app server

cd /rails/app/folder/
puma -e production -d -b unix:///tmp/app_name.sock --pidfile /tmp/

To verify whether the puma process is running:

ps aux | grep puma

To stop the app server

kill -s SIGTERM `cat /tmp/`

Discussion, links, and tweets