Homestead vagrant HTTP请求从主机缓慢,而不是来自guest虚拟机

时间:2018-06-07 16:01:04

标签: laravel vagrant virtualbox homestead vagrantfile

我有一个默认的宅基地配置,运行基于Laravel的API。当我从VM内部向API端点发出curl请求时,我会在~200 ms内收到响应。但是,当我从主机发出相同的卷曲请求时,需要大约6秒钟。

我修改了主机osx / etc / hosts文件,将域指向访客IP(192.168.10.10 api.example.local)。

我尝试添加以下每个虚拟框配置选项而不做任何更改:

vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]

vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]

vb.customize ["modifyvm", :id, "--nictype1", "82540EM"]

Homestead.yaml

---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/Code
      to: /home/vagrant/Code
      type: "nfs"

sites:
    - map: api.example.local
      to: /home/vagrant/Code/api.example.local/public

databases:
    - api

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

require 'json'
require 'yaml'

VAGRANTFILE_API_VERSION ||= "2"
confDir = $confDir ||= File.expand_path(File.dirname(__FILE__))

homesteadYamlPath = confDir + "/Homestead.yaml"
homesteadJsonPath = confDir + "/Homestead.json"
afterScriptPath = confDir + "/after.sh"
aliasesPath = confDir + "/aliases"

require File.expand_path(File.dirname(__FILE__) + '/scripts/homestead.rb')

Vagrant.require_version '>= 1.9.0'

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"
        end
    end

    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
    end

    if defined? VagrantPlugins::HostsUpdater
        config.hostsupdater.aliases = settings['sites'].map { |site| site['map'] }
    end

    config.vm.provider :virtualbox do |vb|
      vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    end
end

在编辑guest虚拟机和主机之间共享的文件时,似乎没有任何延迟,只有HTTP请求。

我错过了什么吗?或者这种速度通常吗?

0 个答案:

没有答案