【问题标题】:Vagrant Port Fowarding on WindowsWindows 上的 Vagrant 端口转发
【发布时间】:2015-06-11 13:37:27
【问题描述】:

我在 Stack Overflow 上查看了其他一些线程并找到了一些解决方案,但没有什么对我有用。我正在运行默认使用端口 3000 的 Rails 服务器(使用 Puma)。

在虚拟机上运行rails s

=> Booting Puma
=> Rails 4.2.1 application starting in development on http://localhost:3000

流浪文件

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.hostname = 'rails-dev-box'
  config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id, "--memory", "2048"]
  end
  config.vm.network :forwarded_port,   guest: 3000, host: 3000, auto_correct: true
  config.vm.provision :shell, path: 'bootstrap.sh', keep_color: true
end

在虚拟机上运行curl 'http://0.0.0.0:3000'curl 'http://127.0.0.1:3000'curl 'http://localhost:3000' (正确)

<!DOCTYPE html>
<html>
  <head>
    <title>Page Title</title>
    <meta name="csrf-param" content="authenticity_token" />
    <meta name="csrf-token" content="xQKai5cQ" />
  </head>
  <body>
    <h1>You've Made It!!</h1>
  </body>
</html>

在本地机器上运行curl 'http://127.0.0.1:3000'curl 'http://localhost:3000'

* Adding handle: conn: 0x87e8a8
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x87e9a8) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 3000 (#0)
*   Trying ::1...
* Connection Refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.30.0
> Host: localhost:3000
> Accept: */*
>
* Recv failure: Connection was aborted
* Closing connection 0
curl: (56) Recv failure: Connection was aborted

打开浏览器只会给我一个空白页面,说连接不可用。

感谢任何帮助。谢谢!

【问题讨论】:

    标签: ruby-on-rails vagrant virtual-machine


    【解决方案1】:

    使用这个命令:

    rails s -b 0.0.0.0
    

    【讨论】:

    • 做到了!谢谢:D
    猜你喜欢
    • 1970-01-01
    • 2016-01-13
    • 2013-06-17
    • 1970-01-01
    • 2013-08-28
    • 1970-01-01
    • 2011-04-12
    • 1970-01-01
    • 2014-07-30
    相关资源
    最近更新 更多