How do I deploy my rails application?

May 14, 2016 395 views
Deployment DNS Nginx Ruby on Rails

My rails application is running on how do I point my
domain to this port? What is the best way to deploy my rails app?

First, I've finished pointing my domain name to DigitalOcean by following this tutorial.

Afterward, I setup a new host name in DigitalOcean by following this ( tutorial.

Now, I'm trying to reconfigure my server with between rails, ngnix, and unicorn by following this tutorial which I am running into problems.

I have reconfigured everything according to the tutorial but the problem I am running into now is starting unicorn. I follow the tutorial to the section called "Create Unicorn Init Script" however when I run
sudo service unicorn_appname start,
I get this error
Starting rails
/usr/local/rvm/gems/ruby-2.2.1/gems/unicorn-5.1.0/lib/unicorn/configurator.rb:88:in `block in reload': directory for pid=/home/rails/shared/pids/ not writable (ArgumentError)

I am not sure if this is the tutorial I should follow. Or is there an easier and better way for me to point my domain name to my rails app running in DigitalOcean. Reconfiguring ngnix to take incoming request to port 3000? I really don't know much about unicorn and ngnix. But I'll be happy to learn the right way to do this.

Anyways, please help!

1 Answer

While unicorn will help manage your app you can also do a more simple deply using screen and nginx. Using this method your app will not automatically restart if it were to crash.

To do this, first install screen

sudo apt-get update
sudo apt-get install screen

Then adjust your /etc/nginx/sites-enabled/default file to read:

server {
    listen 80;

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

Then create a new screen session:


Then run your application. Once it is running, you can detach your shell by pressing Ctrl-a and then d

You can re-attach to your screen session using screen -r

Now just restart nginx to have your proxy setup take effect:

service nginx restart

This will work fairly well for smaller scale sites but unicorn does provide a better method for production applications.

Have another answer? Share your knowledge.