Search code examples
ruby-on-railsthin

How can I change the port that thin binds to when starting a Rails server?


I inherited a Rails application, and I'm trying to understand it. However, when I run:

rails s

I receive this log:

=> Booting Thin
=> Rails 3.2.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop

However, this seems problematic to me, as both servers are trying to listen on 3000. What makes rails launch thin when I run rails s?


Solution

  • When the thin gem is installed rails will use that as a server by default.

    You can change the port with the -p option, for example -p 3001. There are also some more options available to set environment, bind address and similar. There is more info on those in the Rails guide.