How to run rails s -p80 on 80 port?
Ruby on-RailsRuby on-Rails-3Ruby on-Rails Problem Overview
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
Ruby on-Rails Solutions
Solution 1 - Ruby on-Rails
rvmsudo rails server -p 80
Solution 2 - Ruby on-Rails
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?
Solution 3 - Ruby on-Rails
Was going to suggest
rails=`which rails` ; sudo $rails server -p 80
but that still tries to use the global gemset and not the project gemset from RVM. So...
-
Make sure sshd is running on your Mac. (System Prefs => Sharing => Remote Login checked)
-
Make sure
rails s
is running on port 3000 as your non-root user -
Open a new terminal and...
me=``whoami``; sudo ssh -L 80:127.0.0.1:3000 -l $me -N localhost
(BTW reduce the duplicate `'s to singular ones in the line above, I cannot figure out how escape it properly here.)
The first Password:
is your root
user, the second is the password for whomever whoami
returns.
Though you probably want to install Phusion Passenger and set it up under your local Apache. Unless you are just trying to demo something real quick and this is not a permanent solution of course.
Solution 4 - Ruby on-Rails
If you are using RVM, and you did the default setup, then you shouldn't use sudo
.
Just:
mlzboy@mlzboy-MacBook ~/my/b2c2 $ rails server -p 80
However 80 is a privileged port, so you need to run as root, and you will have follow the instructions for Multi-User installation of RVM.
Solution 5 - Ruby on-Rails
you can start server on port 80
rails s -p 80
If port 80 does not bind(other processes is not using to port 80).