I am running a Wordpress app inside a Vagrant box that needs to access a Rails app running on my host machine (using Pow). How do I do that?

I can access the Rails app on my host machine using myapp.dev and would like to access it from inside Vagrant as well, in the best case using the same domain.

All info I could find on that topic is about the other way around, where you want to access an app running inside Vagrant from the host machine.

有帮助吗?

解决方案

So it just sounds like you need a host entry on your guest machine pointing back your host machine?

You could do something like the following:

Vagrant.configure("2") do |config|
    require 'socket'
    local_ip = UDPSocket.open {|s| s.connect("64.233.187.99", 1); s.addr.last}
    config.vm.provision "shell", inline: "echo \"#{local_ip} myapp.dev\" >> /etc/hosts"
end

This should use a socket to get your host machines IP address and then using a shell provisioner it will append that IP address to your hosts file which should allow your VM to use the domain name you want to communicate with your host OS.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top