辛星浅析rails server监听机器外部机器无法访问的问题

来源:转载


    最近开始写ruby的教程,在虚拟机搭建了rails之后,发现在虚拟机中可以访问,但是外网无法访问,这里说一下具体的问题把,这是因为rails  server的默认监听设置造成的。

    我们可以使用rails  server  -h来查看它的默认监听设置,它默认监听的是'localhost‘这个主机名,导致我们无法访问,解决思路就是设置为绑定为一个ip地址,比如虚拟机的内网地址。

    下面是我的测试范例(下面的GET是一次网页的访问请求):

[email protected]:~/blog# rails server -b 192.168.31.114
Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring.
=> Booting WEBrick
=> Rails 4.2.4 application starting in development on http://192.168.31.114:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-11-10 17:40:04] INFO  WEBrick 1.3.1
[2015-11-10 17:40:04] INFO  ruby 2.1.2 (2014-05-08) [i386-linux-gnu]
[2015-11-10 17:40:04] INFO  WEBrick::HTTPServer#start: pid=13044 port=3000




Started GET "/" for 192.168.31.238 at 2015-11-10 17:40:07 +0800
Cannot render console from 192.168.31.238! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Rails::WelcomeController#index as HTML
  Rendered /var/lib/gems/2.1.0/gems/railties-4.2.4/lib/rails/templates/rails/welcome/index.html.erb (1.1ms)
Completed 200 OK in 17ms (Views: 6.5ms | ActiveRecord: 0.0ms)



分享给朋友:
您可能感兴趣的文章:
随机阅读: