简体   繁体   中英

Access vagrant VM with puphpet from local network?

I used vagrant and puphpet for two weeks and it works great. In my case I'll just use http://myserver.dev that I added to my host file as puphpet suggest

192.168.56.101 myserver.dev

Now I want to get access to my VM:s apache www folder from another computer in my local network.

This post suggest to uncomment some lines in vagrant file, but as I use puphpet my autogenerated vagrant file looks like this:

# -*- mode: ruby -*-

dir = File.dirname(File.expand_path(__FILE__))

require 'yaml'
require "#{dir}/puphpet/ruby/deep_merge.rb"
require "#{dir}/puphpet/ruby/to_bool.rb"
require "#{dir}/puphpet/ruby/puppet.rb"

configValues = YAML.load_file("#{dir}/puphpet/config.yaml")

provider = ENV['VAGRANT_DEFAULT_PROVIDER'] ? ENV['VAGRANT_DEFAULT_PROVIDER'] : 'local'
if File.file?("#{dir}/puphpet/config-#{provider}.yaml")
  custom = YAML.load_file("#{dir}/puphpet/config-#{provider}.yaml")
  configValues.deep_merge!(custom)
end

if File.file?("#{dir}/puphpet/config-custom.yaml")
  custom = YAML.load_file("#{dir}/puphpet/config-custom.yaml")
  configValues.deep_merge!(custom)
end

data = configValues['vagrantfile']

Vagrant.require_version '>= 1.8.1'

Vagrant.configure('2') do |config|
  eval File.read("#{dir}/puphpet/vagrant/Vagrantfile-#{data['target']}")
end

But there are no uncomment lines.

I thought maybe I need to do something in puphpet's config.yaml? Here's what I've found about ip and port:

machines:
    vflm_azud9vpjzelv:
        id: machine1
        hostname: myserver.puphpet
        network:
            private_network: 192.168.56.101
            forwarded_port:
                vflmnfp_rkr38vlo4vcb:
                    host: '6597'
                    guest: '22'
        memory: '512'
        cpus: '1'

You have two simple choices:

  • Vagrant comes with the vagrant share command that opens up a publicly-accessible, random URL to your VM
  • Create a forwarded port from your host to your VM. For example, forward port 1080 on your host to port 80 in the VM, so when you go to http://localhost:1080 traffic will be forwarded to your VM. For this you need to set * as your Apache vhost's alias so it catches all traffic to the port you choose (in this case, 80).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM