Vagrant 局域网访问
Posted mrshao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Vagrant 局域网访问相关的知识,希望对你有一定的参考价值。
开发中需要和前端或其他后端同事配合,需要直接访问我本机开发环境
在vagrant文件夹中的Vagrantfile配置下即可:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
if File.exist? aliasesPath then
config.vm.provision "file", source: aliasesPath, destination: "/tmp/bash_aliases"
config.vm.provision "shell" do |s|
s.inline = "awk \'{ sub(\\"\\r$\\", \\"\\"); print }\' /tmp/bash_aliases > /home/vagrant/.bash_aliases && chown vagrant:vagrant /home/vagrant/.bash_aliases"
end
end
#配置公有静态IP访问,我的局域网IP是10.0.1.124,这里我给配置成223了,确保没被占用就行
config.vm.network "public_network", ip: "10.0.1.223"
if File.exist? homesteadYamlPath then
settings = YAML::load(File.read(homesteadYamlPath))
elsif File.exist? homesteadJsonPath then
settings = JSON::parse(File.read(homesteadJsonPath))
else
abort "Homestead settings file not found in #{confDir}"
end
Homestead.configure(config, settings)
if File.exist? afterScriptPath then
config.vm.provision "shell", path: afterScriptPath, privileged: false, keep_color: true
end
if File.exist? customizationScriptPath then
config.vm.provision "shell", path: customizationScriptPath, privileged: false, keep_color: true
end
if Vagrant.has_plugin?(\'vagrant-hostsupdater\')
config.hostsupdater.remove_on_suspend = false
config.hostsupdater.aliases = settings[\'sites\'].map { |site| site[\'map\'] }
elsif Vagrant.has_plugin?(\'vagrant-hostmanager\')
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.aliases = settings[\'sites\'].map { |site| site[\'map\'] }
end
end
配置完后记得vagrant reload下
以上是关于Vagrant 局域网访问的主要内容,如果未能解决你的问题,请参考以下文章