允许公共连接到本地 Ruby on Rails 开发服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9282689/
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
Allow public connections to local Ruby on Rails Development Server
提问by Dan
I am setting up a RoR development environment on a Windows machine. I was wondering how I can set it up so a few friends of mine can have access to the web server and monitor the progress?
我正在 Windows 机器上设置 RoR 开发环境。我想知道如何设置它以便我的几个朋友可以访问网络服务器并监控进度?
It would only be 2 or 3 people connecting at anytime time max.
最多只有 2 或 3 人在任何时间连接。
采纳答案by David Underwood
Give localtunnela go. It's a ruby gem so you shouldn't have any problem getting it going:
给localtunnel一去。这是一颗红宝石,所以你应该不会有任何问题:
gem install localtunnel
localtunnel 3000
The first time you do that it'll ask you for an ssh key, but once you've got that set it'll show you the public url that you can share. Anything running on the specified port will get exposed at that url.
第一次这样做时,它会要求您提供 ssh 密钥,但是一旦您获得了该设置,它就会向您显示可以共享的公共 url。在指定端口上运行的任何内容都将在该 url 上公开。
Showoff-io looks like a similar service, but I haven't used it so I can't comment. Also, it's paid and requires signup.
Showoff-io 貌似是一个类似的服务,但是我没用过所以无法评论。此外,它是付费的,需要注册。
回答by JellicleCat
The simplest way requires NO additional installations: just add a single option to your rails server(or rails s) command when you start up the server:
最简单的方法不需要额外的安装:只需在启动服务器时向您的rails server(或rails s)命令添加一个选项:
rails s --binding=0.0.0.0
The 0.0.0.0address means "listen to requests from anywhere." On many systems, the default is 127.0.0.1, which means "listen to requests from localhost only."
该0.0.0.0地址的意思是“听取来自任何地方的请求”。在许多系统上,默认值为127.0.0.1,这意味着“仅侦听来自本地主机的请求”。
(If you don't also specify a -por --portoption, then the port shall be 3000, as usual.)
(如果您还没有指定 a-p或--port选项,那么端口应该是3000,像往常一样。)
回答by meagar
You can tell your development server to listen on your publicly accessible interface:
您可以告诉您的开发服务器监听您的可公开访问的接口:
If you're running a server via rails server, you can specify the IP to listen on via -b <ip>or --binding=<ip>. By default, the server listens on 0.0.0.0, that is, only for local connections.
如果您通过 运行服务器rails server,则可以指定 IP 以通过-b <ip>或进行侦听--binding=<ip>。默认情况下,服务器侦听 0.0.0.0,即仅用于本地连接。
Usage: rails server [mongrel, thin, etc] [options]
-p, --port=port Runs Rails on the specified port.
Default: 3000
-b, --binding=ip Binds Rails to the specified ip.
Default: 0.0.0.0
You can instead find out what your machine's network address is and bind to that address instead, but you will have to forward ports and figure out what your publicly routable IP address is on the Internet; this is outside the bounds of Stack Overflow.
相反,您可以找出您机器的网络地址并绑定到该地址,但您必须转发端口并找出您在 Internet 上的可公开路由的 IP 地址;这超出了堆栈溢出的范围。
回答by Zyphrax
Allow remote connections by binding the Rails server to 0.0.0.0.
通过将 Rails 服务器绑定到 0.0.0.0 来允许远程连接。
Here's the short notation for those who don't like typing :
对于那些不喜欢打字的人,这是简短的表示法:
bin/rails s -b 0.0.0.0
If you also want to allow IPv6 connections (Puma):
如果您还想允许 IPv6 连接 (Puma):
bin/rails s -b [::]

