XAMPP中Apache虚拟主机配置问题:自定义域名无法访问
Let’s walk through fixing this issue — I’ve dealt with plenty of finicky virtual host configs in XAMPP, so here’s what to check step by step:
First, Verify the Basics
Before diving into configs, confirm the core setup works:
- On your remote device, try accessing
192.168.1.134:8081/db.htmldirectly. If this loads, your Apache server and file path are good — the problem is with domain resolution or virtual host configuration. - If this doesn’t load, double-check Apache is running, your firewall allows incoming traffic on port 8081, and the file
C:/xampp/htdocs/Dashboard/db.htmlexists with correct permissions.
1. Fix Remote Device Hosts File (Critical!)
You only updated the server’s hosts file, but your remote device needs to know where dashboard.com points to. On the remote device:
- Windows: Edit
C:\Windows\System32\drivers\etc\hosts(run Notepad as admin) and add:192.168.1.134 dashboard.com - Mac/Linux: Edit
/etc/hosts(usesudo nano /etc/hosts) and add the same line. - Mobile: You’ll need a root-enabled device or a DNS app to override hosts, since mobile OSes don’t let you edit hosts directly easily.
2. Clean Up Your Virtual Host Config (httpd-vhosts.conf)
Your current config has outdated syntax and structure. Replace it with this Apache 2.4-compatible version:
<VirtualHost *:8081> DocumentRoot "C:/xampp/htdocs/Dashboard" ServerName dashboard.com <Directory "C:/xampp/htdocs/Dashboard"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Require all granted </Directory> </VirtualHost>
Key fixes here:
- Removed
NameVirtualHost(it’s deprecated in Apache 2.4+ and no longer needed). - Moved the
<Directory>block inside the<VirtualHost>to avoid conflicts with your httpd.conf settings. - Used modern Apache 2.4 authorization (
Require all granted) instead of the oldOrder allow,denysyntax.
3. Access with the Correct Port
Your Apache is listening on port 8081, so you need to include it in your URL when accessing from the remote device:
dashboard.com:8081/db.html
If you want to skip the port (use just dashboard.com), change your httpd.conf Listen directive to Listen 80 (make sure no other apps like IIS, Skype, or Chrome are using port 80 first).
4. Verify Apache Loads the Virtual Host Config
Double-check that httpd.conf has the virtual hosts include uncommented:
Include conf/extra/httpd-vhosts.conf
After making all config changes, completely stop and restart Apache (don’t just "refresh" — XAMPP’s restart button works for this).
5. Check Apache Error Logs for Clues
If you still have issues, look at Apache’s error log at C:/xampp/apache/logs/error.log. It will tell you if there’s a syntax error in your config, path issues, or permission problems — this is the best way to debug tricky Apache problems.
内容的提问来源于stack exchange,提问作者Pablo Marina

