Question

I am running a Sinatra application locally.

Ever since I installed Thin, my Sinatra app always uses it as the web server. However, I have been having performance issues with Thin serving the large amount of static files required by my application, and I would like to switch to either Mongrel or WEBrick.

I cannot seem to figure out how to switch my application over to Mongrel or WEBrick. Even when I put require 'mongrel' or require 'webrick' at the top of my app.rb, upon a ruby app.rb, Sinatra still starts with Thin.

So, my question is: how do you specify the web server for Sinatra to use in development mode? Also, how could I do so in production mode?

Was it helpful?

Solution

You can set the server Sinatra uses with the :server configuration setting:

set :server, 'webrick'  # or thin, mongrel

In production, it is much better to use a more sophisticated server like Phusion Passenger or Unicorn, since they have better performance than Thin, Mongrel, or WEBrick. If you choose Passenger or Unicorn, you would not configure the server within your Sinatra application file itself, but instead typically configure it separately using a Rackup config.ru file.

"Ruby on Rails Server options" is aimed at Rails applications, but is still very relevant for Sinatra apps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top