Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run rails s -p80 on 80 port?

By default,

 rails s #running on 3000 port 

Now I want to run it on port 80. So I tried:

 sudo rails -s -p80 

But it threw an error:

mlzboy@mlzboy-MacBook ~/my/b2c2 $ sudo rails s -p80 sudo: rails: command not found 

I used rvm to install ruby & rails. It seems rvm is user specified. Is it not able to find rails in root?

I also tried below code:

mlzboy@mlzboy-MacBook ~/my/b2c2 $ which rails /home/mlzboy/.rvm/gems/ruby-1.9.2-p0/bin/rails mlzboy@mlzboy-MacBook ~/my/b2c2 $ sudo /home/mlzboy/.rvm/gems/ruby-1.9.2-p0/bin/rails s -p80 
like image 594
mlzboy Avatar asked Dec 04 '10 03:12

mlzboy


People also ask

How do I run a rails on a different port?

Go to your browser and open http://localhost:3000, you will see a basic Rails app running. You can also use the alias "s" to start the server: bin/rails s . The server can be run on a different port using the -p option.

What port does rails run on?

You can call Rails::Server. new. options[:Port] to get the port that your Rails server is running on. This will parse the -p 3001 args from your rails server command, or default to port 3000 .


2 Answers

rvmsudo rails server -p 80 
like image 126
iain Avatar answered Oct 15 '22 03:10

iain


Just forward the request from port 80 to 3000 using below command:

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

Another option is:

rvmsudo rails server -p 80 

However please remember to free this port from Apache or other services which consume this port normally. Also, I m not sure giving sudo permission to RVM may have any security issue or not?

like image 30
2 revs Avatar answered Oct 15 '22 01:10

2 revs