How can I deploy a Sinatra app?

March 31, 2015 2.5k views
Sinatra Ruby DigitalOcean Ubuntu

I've transferred all files to my droplet. is still not responding. I assume it's because the Sinatra server isn't running. How can I resolve this?

1 comment
1 Answer

To deploy a sinatra app you will need to do the following:

1.) Install the sinatra gem with:

gem install sinatra

If you encounter errors building the gem you may need to install some additional libraries and tools:

apt-get update
apt-get install ruby-dev build-essential

2.) Install Nginx to act as a proxy between your app and the public Internet on port 80.

apt-get install nginx

3.) Edit your nginx configuration file /etc/nginx/sites-enabled/default Something like the following should be used to replace the default Location / block:

location / {
    proxy_pass       http://localhost:4567;
    proxy_set_header Host      $host;
    proxy_set_header X-Real-IP $remote_addr;

4.) Now restart nginx and start your sinatra app.

service nginx restart
ruby myapp.rb

Your app will now be up and running and available via a web browser.

Since Ruby will run in the console you may want to use screen to keep the app running in the background once you disconnect. To do this first install screen if it is not already there:

apt-get install screen

Then start a new screen session:

screen -S "My App"

and run your app within the session:

ruby myapp.rb

Once it's up and running you can disconnect from the screen session by pressing **Ctrl+a" and then "d"

Have another answer? Share your knowledge.