How can I deploy a Sinatra app?

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?

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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”