21

I'm learning thin server, by now I can use thin start to fire up the server, but the port is 3000, I should type the localhost:3000 in the browser to get the webpage.

I want to take off the 3000 port as we normally do with other site. So I set use the command thin -p 80 start to use the default http port. But I got this error:

root@makserver:~/apps/videosite# thin --port 80 start
>> Using rack adapter
>> Thin web server (v1.2.7 codename No Hup)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:80, CTRL+C to stop
/usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:572:in `start_tcp_server': no acceptor (RuntimeError)
    from /usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:572:in `start_server'
    from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/backends/tcp_server.rb:16:in `connect'
    from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/backends/base.rb:49:in `block in start'
    from /usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `call'
    from /usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
    from /usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
    from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/backends/base.rb:57:in `start'
    from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/server.rb:156:in `start'
    from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/controllers/controller.rb:80:in `start'
    from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/runner.rb:177:in `run_command'
    from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/runner.rb:143:in `run!'
    from /usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/bin/thin:6:in `<top (required)>'
    from /usr/local/bin/thin:19:in `load'
    from /usr/local/bin/thin:19:in `<main>'
peterh
  • 11,875
  • 18
  • 85
  • 108
mko
  • 21,334
  • 49
  • 130
  • 191

9 Answers9

25

This indicates the port might be already in use.

Also, try running it with administrator privileges

sudo thin start -p 80

(Thanks to Tom Crinson for his blog article.)

Simon Perepelitsa
  • 20,350
  • 8
  • 55
  • 74
24

Looks like an old Ruby process has hung somewhere.

Fire up activity monitor and kill all Ruby processes.

Or use the terminal:

ps -e | grep "ruby"

then:

kill {process id}
zishe
  • 10,665
  • 12
  • 64
  • 103
Stefan Fountain
  • 361
  • 2
  • 6
20
rvmsudo rails server thin -p 80
zishe
  • 10,665
  • 12
  • 64
  • 103
  • 1
    This gave me the same "/usr/bin/env: ruby: No such file or directory" error as `sudo thin start -p 80`. In what way is running rvmsudo different? – Day Davis Waterbury Jul 03 '12 at 17:27
12

If you don't want to run sudo to start up the webserver (maybe the user isn't a sudoer), you can always go in as a superuser, and set up redirection for port 80 traffic to port x:

sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000
sudo iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 3000

To lookup the iptables

sudo iptables --list -n -t nat
sudo iptables --list -n

This way you can run the webserver as another user who isn't as privileged.

Credit goes to this post

Community
  • 1
  • 1
Louis Sayers
  • 2,162
  • 3
  • 30
  • 53
5

Traditionally, port 80 is a privileged port (all of them below 1024 are, actually) so you need to have superuser privileges to bind to it.

Looking over the docs, they suggest running it behind nginx, which is generally a good idea. Assuming you used your package manager to install nginx, you probably received instructions on how to make nginx start at boot, and it will bind to port 80 by default.

Hank Gay
  • 70,339
  • 36
  • 160
  • 222
  • I just install the nginx, but when I get it start, some error occurred `[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)` BTW my server is running on VPS – mko Feb 24 '11 at 06:00
  • 1
    @yozloy As @Semyon Pereplitsa said, this means something is already bound on that port (most commonly Apache). To find out what is doing it on your server, try running `lsof -i :80` (assuming you have `lsof` installed; if not, do that first). Assuming that it is Apache and you'd like to use nginx instead, you should probably uninstall Apache, or change your startup settings so it doesn't start by default (how to do this depends on your OS). – Hank Gay Feb 24 '11 at 14:13
1

I couldn't make Thin run on port 80 using sudo because I had installed Ruby using RVM, and the root user didn't have access to it. Also, I had to set an environment variable before running Thin to set my mongodb access URL. The following line did it for me:

rvmsudo MONGODB_URI=MY_MONGO_URI thin start -p 80 -d
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Vineel Shah
  • 960
  • 6
  • 14
1

check out this thread Ruby on Rails Server options

it is not recommended to expose 'thin' directly to the internet through port 80. You should use Apache as the web-server and redirect the http request to the thin application server. you can add this to your httpd.conf to redirect the traffic to rails

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
<VirtualHost *:80>
    ServerName YOUR SERVER NAME
    DocumentRoot YOUR ROOT
    ProxyPass / http://YOURSITE.com:3000/
    ProxyPassReverse / http://YOURSITE.com:3000/
    ProxyPreserveHost On
</VirtualHost>
Community
  • 1
  • 1
David Zhan Liu
  • 474
  • 5
  • 8
-1

You can try using 8080 port. We do it with our GWT applications and it's more convenient anyway, rather then 3000.

-1

Maybe try "sudo bundle exec thin start -p 80"?