Ruby-on-rails 如何在 80 端口上运行 rails s -p80?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4351844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run rails s -p80 on 80 port?
提问by mlzboy
By default,
默认情况下,
rails s #running on 3000 port
Now I want to run it on port 80. So I tried:
现在我想在端口 80 上运行它。所以我尝试了:
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?
我使用 rvm 来安装 ruby 和 rails。看来 rvm 是用户指定的。是不是无法在 root 中找到 rails?
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
回答by iain
rvmsudo rails server -p 80
回答by Dinesh Saini
Just forward the request from port 80 to 3000 using below command:
只需使用以下命令将请求从端口 80 转发到 3000:
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?
但是请记住从 Apache 或其他正常使用此端口的服务中释放此端口。另外,我不确定授予 RVM sudo 权限是否有任何安全问题?
回答by cfeduke
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...
但这仍然尝试使用全局 gemset 而不是来自 RVM 的项目 gemset。所以...
- Make sure sshd is running on your Mac. (System Prefs => Sharing => Remote Login checked)
- Make sure
rails sis 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
- 确保 sshd 在您的 Mac 上运行。(系统偏好设置 => 共享 => 远程登录已选中)
- 确保
rails s以非 root 用户身份在端口 3000 上运行 打开一个新终端,然后...
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.)
(顺便说一句,在上面的行中将重复的 `'s 减少为单数,我不知道如何在这里正确地转义它。)
The first Password:is your rootuser, the second is the password for whomever whoamireturns.
第一个Password:是您的root用户,第二个是whoami返回者的密码。
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.
尽管您可能想要安装 Phusion Passenger 并将其设置在您本地的 Apache 下。除非你只是想快速演示一些东西,这当然不是一个永久的解决方案。
回答by Swanand
If you are using RVM, and you did the default setup, then you shouldn't use sudo.
如果您使用的是 RVM,并且进行了默认设置,则不应使用sudo.
Just:
只是:
mlzboy@mlzboy-MacBook ~/my/b2c2 $ rails server -p 80
However 80 is a privileged port, so you needto run as root, and you will have follow the instructions for Multi-User installationof RVM.
回答by uma
you can start server on port 80
您可以在端口 80 上启动服务器
rails s -p 80
If port 80 does not bind(other processes is not using to port 80).
如果端口 80 未绑定(其他进程未使用端口 80)。

