我在Mac上使用 Homestead + Vagrant + Virtualbox 。
问题
虽然我发现了很多解决慢响应时间(例如TTFB)的线程/答案,但是它们都不起作用。我的响应时间在25到32秒之间变化,这显然对于本地开发来说是不可接受的。
建议的解决方案
我从这里尝试了很多建议的解决方案:https://github.com/laravel/homestead/issues/901
并且还阅读并尝试了以下这些线程的许多建议:
- Very Slow Responses On Homestead
- Vagrant Homestead slow
- vagrant slow page load after 60 seconds from last request
- Speed up sync latency between host and guest on Vagrant (NFS sync folders)
即使已经接受了答案,但没有一个能帮助我。
禁用xdebug
我可以这么说 像说明的here一样禁用xdebug 可以帮助我节省5秒钟。
更改光盘大小
按照建议here并按照here的说明将VM的磁盘大小从动态更改为固定时,根本没有帮助(结果更糟)。
根据建议here使用NFS(同步文件夹)
也将宅基地/流浪者设置为NFS并没有帮助。
尝试过(无效文件):
Vagrant.configure("2") do |config|
config.vm.synced_folder ".","/vagrant",type: "nfs",mount_options:['nolock,vers=3,udp,noatime,actimeo=1']
end
也尝试过(homestead.yaml)
folders:
-
map: '/Users/myuser/PhpstormProjects/example.com'
to: /home/vagrant/code
type: "nfs"
options:
mount_options: ['nolock','vers=3','udp','noatime','actimeo=1']
在这两种情况下NFS都可以正常工作,但是它并没有改变有关页面加载时TTFB的情况。
设置natdnshostresolver:关闭
我还尝试根据建议here关闭natdnshostresolver 它并没有改变任何事情。
调整Virtualbox图像
当然,我也尝试增加RAM,CPU,图形等内容,但是如您所见,这没有帮助。
还有其他建议
截至目前,我也愿意尝试valet或您可以提供的其他任何建议/解决方案。
非常感谢!
更新1
在我的VM上更改 nginx.conf (在@emotality建议进行调整之后)确实有所帮助。为了完整性和可能性,可能还要进行一些调整,这是nginx.conf文件的整个http部分。
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
# keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
keepalive_disable none;
keepalive_requests 200;
keepalive_timeout 300s;
server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3,ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
更新2
homestead.yaml的内容:
ip: 192.168.10.14
memory: 4096
cpus: 2
provider: virtualbox
natdnshostresolver: off
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
-
map: '/Users/myUser/PhpstormProjects/exampleproject.com'
to: /home/vagrant/code
type: "nfs"
options:
mount_options: ['nolock','actimeo=1']
sites:
-
map: exampleproject.local
to: /home/vagrant/code
databases:
- homestead
features:
-
mariadb: false
-
ohmyzsh: false
-
webdriver: false
name: exampleproject
hostname: exampleproject
Vagrantfile的内容:
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'json'
require 'yaml'
VAGRANTFILE_API_VERSION ||= "2"
confDir = $confDir ||= File.expand_path("vendor/laravel/homestead",File.dirname(__FILE__))
homesteadYamlPath = File.expand_path("Homestead.yaml",File.dirname(__FILE__))
homesteadJsonPath = File.expand_path("Homestead.json",File.dirname(__FILE__))
afterScriptPath = "after.sh"
customizationScriptPath = "user-customizations.sh"
aliasesPath = "aliases"
require File.expand_path(confDir + '/scripts/homestead.rb')
Vagrant.require_version '>= 2.2.4'
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 " + File.dirname(__FILE__)
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,keep_color: true
end
if Vagrant.has_plugin?('vagrant-hostsupdater')
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