辛星浅析rails server监听机器外部机器无法访问的问题
2015-11-10 17:45
381 查看
最近开始写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] 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)
我们可以使用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] 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)
相关文章推荐
- inheritPrototypeChain.js
- Failed to connect to the configuration database(Sharepoint 2013配置向导失败)
- AIDL的简单运用实现
- Hackshanghai 黑马
- LeetCodeOJ_217_Contains Duplicate
- HDU 1022 Train Problem I
- * daemon not running. starting it now * ADB server didn't ACK * failed to start daemon *
- augustus, gene prediction, trainning
- 简单几何(数学公式+凸包) UVA 11168 Airport
- A System for Rapid, Automatic Shader Level-of-Detail
- 着色器的细节层次技术 Shader Level of Detail
- 开源IDS系列--snorby 2.6.2 undefined method `run_daily_report' for Event:Class (NoMethodError)
- 关于 音频播放器 MediaRecorder(10402): start failed: -22的问题
- RAID 5
- LightOJ 1038 - Race to 1 Again(dp)
- 【HDU】2966 In case of failure【KD树】
- remount of system failed: Permission denied
- AIX5.3以后的版本可以动态缩小文件系统的空间
- Batch Processing Details
- AIX系统设置tffp server