How to start thin on the default port?
Asked Answered
G

9

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>'
Geaghan answered 24/2, 2011 at 3:47 Comment(1)
is there something else running on port 80?Birkner
P
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.)

Petrosal answered 24/2, 2011 at 3:55 Comment(2)
Mokiato's answer should help you.Petrosal
"This indicates the port might be already in use." - bingo. Thanks! (Seems like the error message 'the port is in use' was also in use when they were building Thin.)Roadster
P
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}
Plagiary answered 15/4, 2012 at 17:6 Comment(1)
Exactly what I needed, and love the command line answer. Plus plus.Centuplicate
R
20
rvmsudo rails server thin -p 80
Rhyton answered 1/4, 2012 at 8:20 Comment(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?Contradance
F
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

Frigate answered 28/4, 2012 at 21:12 Comment(2)
Of all the solutions offered here (thanks everyone), this is the one that worked for me. Thanks Louis!Contradance
This is also a general solution for various port restrictionsFlourishing
C
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.

Croteau answered 24/2, 2011 at 3:55 Comment(2)
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 VPSGeaghan
@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).Croteau
D
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
Diagnosis answered 16/9, 2012 at 1:40 Comment(0)
H
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>
Hypodermic answered 14/7, 2013 at 8:52 Comment(0)
T
-1

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

Tarah answered 15/9, 2012 at 15:43 Comment(0)
L
-1

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

Lukash answered 28/2, 2014 at 19:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.