Windows8.1宿主机VirtualBox LAMP服务器仅index.html可访问的问题求助
看起来你遇到的是文件路径匹配错误或者Apache目录权限/配置限制导致的404问题,咱们一步步排查解决:
1. 先确认访问路径是否正确
你提到basics.html在vboxshare目录下,而你的DocumentRoot是/var/www/html,那这个文件的实际路径应该是/var/www/html/vboxshare/basics.html。对应的访问URL应该是:
http://techbox.test:8080/vboxshare/basics.html
而不是直接/basics.html——这个路径会去/var/www/html/basics.html找文件,自然会返回404。如果是你打错了路径,先修正试试。
2. 检查vboxshare目录的权限
如果路径没错还是404,那大概率是Apache进程没有读取这个目录和文件的权限。登录到你的虚拟机,执行以下命令调整权限:
# 给目录添加可执行权限(Apache需要遍历目录) sudo chmod +x /var/www/html/vboxshare # 给文件添加可读权限 sudo chmod +r /var/www/html/vboxshare/basics.html # 确保目录和文件的所属组是Apache运行用户(通常是www-data) sudo chown -R www-data:www-data /var/www/html/vboxshare
3. 完善Apache的VirtualHost配置
你的techbox.conf里没有针对目录的访问规则,需要添加<Directory>块来允许Apache访问这些目录。修改techbox.conf内容如下:
<VirtualHost *:80 *:8080> ServerName techbox ServerAlias *.test DocumentRoot /var/www/html # 根目录访问规则 <Directory /var/www/html> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory> # 针对vboxshare目录的单独配置(如果是VirtualBox共享文件夹更稳妥) <Directory /var/www/html/vboxshare> Options FollowSymLinks Require all granted </Directory> </VirtualHost>
修改后重启Apache服务生效:
sudo systemctl restart apache2
(旧版本Ubuntu系统可使用sudo service apache2 restart)
4. 验证VirtualBox共享文件夹的挂载状态
如果vboxshare是VirtualBox的共享文件夹,还要确认它是否正确挂载到了/var/www/html/vboxshare,并且挂载时设置了适配Apache的权限。执行以下命令查看挂载信息:
mount | grep vboxshare
如果挂载时没有指定uid=www-data,gid=www-data,可以重新挂载:
sudo umount /var/www/html/vboxshare sudo mount -t vboxsf 你的共享文件夹名称 /var/www/html/vboxshare -o uid=www-data,gid=www-data
(把你的共享文件夹名称替换为你在VirtualBox中设置的共享文件夹名称)
按照上面的步骤排查,应该能解决文件无法访问的问题。
内容的提问来源于stack exchange,提问作者A. John
相关产品推荐
相关产品推荐

