新手问题 开发模式局域网如何访问 Rails 程序

loyalpartner · 2015年03月04日 · 最后由 swordray 回复于 2015年05月08日 · 3902 次阅读

局域网 ip 是:192.168.1.103 rails server 启动 rails 后,不能用 http://192.168.1.103:3000 访问吗?

rails s -b 0.0.0.0

亲测是可以直接访问的

我是 rails s -b 192.168.1.101

#3 楼 @cqcn1991 那你本机也得通过 192.168.1.101 访问吧……0.0.0.0 监听全部端口

#4 楼 @cassiuschen 原来是这样。。。。懂了……

http://guides.rubyonrails.org/4_2_release_notes.html 3.3 Default Host for rails server Due to a change in Rack, rails server now listens on localhost instead of 0.0.0.0 by default. This should have minimal impact on the standard development workflow as both http://127.0.0.1:3000 and http://localhost:3000 will continue to work as before on your own machine.

However, with this change you will no longer be able to access the Rails server from a different machine, for example if your development environment is in a virtual machine and you would like to access it from the host machine. In such cases, please start the server with rails server -b 0.0.0.0 to restore the old behavior.

If you do this, be sure to configure your firewall properly such that only trusted machines on your network can access your development server.

如果你的 rails 是最新版本(4.2)你应该这样启动:rails server -b 0.0.0.0

#2 楼 @wanzysky 嘿。。。你也在这里。。

最短写法 rails s -b0

需要 登录 后方可回复, 如果你还没有账号请 注册新账号