Vagrant配置后无法访问localhost站点,寻求解决方法
Hey there, let’s work through why your crm.local site isn’t loading even after setting up Vagrant Homestead. I’ve gone over your config and logs, so here are targeted checks and fixes to get things working:
1. Double-Check Your Hosts File Entry
Even though you mentioned configuring it, let’s confirm the Windows hosts file (located at C:\Windows\System32\drivers\etc\hosts) has the correct line—make sure you edited it with administrator privileges (otherwise changes won’t save):
192.168.10.10 crm.local
Ensure there are no extra spaces or typos, and save the file before proceeding.
2. Verify Network Connectivity to the VM
First, test if your host machine can reach the VM’s IP:
ping 192.168.10.10
If ping fails, check VirtualBox’s network settings for your Homestead VM:
- Open VirtualBox, select your VM, go to Settings > Network
- Confirm Adapter 1 is set to "NAT", and Adapter 2 is set to "Host-Only Adapter" with an IP range matching
192.168.10.x
3. Validate Your Homestead YAML Configuration
Your config looks solid, but let’s confirm a few critical details:
- Folder Mapping: Ensure
D:/Work/crmexists on your Windows machine, with no special characters (spaces, Chinese, etc.) in the path. - Site Root: Confirm the public directory exists inside the VM. Log into the VM and check:
You should see your app’s entry file (likevagrant ssh ls -la /home/vagrant/code/crm/publicindex.php) here.
4. Check Nginx Configuration & Status
Homestead auto-generates Nginx configs, but sometimes they can have issues:
- Log into the VM and view your site’s Nginx config:
Confirm thecat /etc/nginx/sites-available/crm.localrootdirective points to/home/vagrant/code/crm/publicand there are no syntax errors. - Restart Nginx to apply any fixes:
sudo service nginx restart - Verify Nginx is listening on port 80:
You should see a line showingsudo netstat -tulpn | grep nginx0.0.0.0:80if it’s running correctly.
5. Rule Out Firewall Interference
Windows Firewall might block traffic to the VM. Try temporarily disabling it to see if crm.local loads. If it does, add an inbound rule to allow traffic to 192.168.10.10 on port 80.
6. Re-Provision the VM
If the initial setup had errors (common in log outputs), re-run the provisioning process to fix configs:
vagrant provision
Start with the network ping test first—it’s the quickest way to narrow down if the issue is network-related or app/config-related. Let me know which step uncovers the problem!
内容的提问来源于stack exchange,提问作者ToujouAya

