Apache显示默认索引页而非虚拟主机页面,Win10手动部署求助
Hey there, let's work through this virtual host issue together—this is a super common pitfall when moving from XAMPP to a manual Apache setup, so we'll get it sorted quickly!
Here are the key steps to fix your test.com virtual host still showing the default Apache page:
1. Ensure Apache is loading your virtual hosts configuration
First, Apache doesn't load the virtual hosts file by default. You need to enable it in your main httpd.conf:
- Open
C:/Server/Apache24/conf/httpd.confin a text editor - Look for the line that says
#Include conf/extra/httpd-vhosts.conf - Remove the leading
#to uncomment it (this tells Apache to load the virtual hosts config file) - Save
httpd.conf
2. Map test.com to your local machine via the hosts file
Your Windows PC doesn't know where test.com points unless you tell it:
- Open Notepad as Administrator (right-click > Run as administrator)
- Go to
File > Openand navigate toC:\Windows\System32\drivers\etc\hosts(change the file type filter to "All Files" to see it) - Add these lines at the bottom:
127.0.0.1 test.com ::1 test.com - Save the file, then open Command Prompt and run
ipconfig /flushdnsto clear DNS cache
3. Add directory permissions to your virtual host
Your current virtual host config is missing a critical piece: explicit permissions for the test directory. Without this, Apache might block access and fall back to the default page. Update your virtual host config (in conf/extra/httpd-vhosts.conf) to include:
<VirtualHost *:80> DocumentRoot "C:/Server/Apache24/htdocs/test" ServerName test.com # Add this directory block to grant access <Directory "C:/Server/Apache24/htdocs/test"> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory> # Optional: Ensure index.php is prioritized DirectoryIndex index.php index.html </VirtualHost>
4. Restart Apache
Any config changes require a restart to take effect:
- Open the Apache Service Monitor (or use Command Prompt)
- Run
httpd -k restartfromC:/Server/Apache24/bin(or just use the service monitor's restart button)
5. Test with a fresh browser session
Browsers often cache old page data. Try accessing test.com in an incognito/private window to rule out cached content.
After following these steps, test.com should load the content from your C:/Server/Apache24/htdocs/test directory instead of the default Apache page!
内容的提问来源于stack exchange,提问作者John Deck

