最近开始写ruby的教程,在虚拟机搭建了rails之后,发现在虚拟机中可以访问,但是外网无法访问,这里说一下具体的问题把,这是因为rails server的默认监听设置造成的。
我们可以使用rails server -h来查看它的默认监听设置,它默认监听的是'localhost‘这个主机名,导致我们无法访问,解决思路就是设置为绑定为一个ip地址,比如虚拟机的内网地址。
下面是我的测试范例(下面的GET是一次网页的访问请求):
root@newstar:~/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] I