我最近安装了 ubuntu 22.04 并尝试在其上使用 LAMP。
但我对 VirtualHost 有疑问。
我想使用具有本地域的虚拟主机,例如:test.local
我将此域添加到/etc/hosts 并将此配置添加到我的 test.local.conf:
<VirtualHost *:80>
ServerName test.local
ServerAdmin webmaster@localhost
DocumentRoot /home/soroush/Sites/test
<Directory "/home/soroush/Sites/test" >
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
然后运行:a2ensite test.local.conf但是当我在浏览器中打开 test.local 时,apache 显示 403 错误。
站点/测试文件夹和文件具有 0777 权限,所有者是我的用户名。
我应该怎么做才能解决这个问题?
最佳答案
By default, Ubuntu does not allow access through the web browser to any file apart of those located in /var/www, public_html directories (when enabled) and /usr/share (for web applications). If your site is using a web document root located elsewhere (such as in /srv) you may need to whitelist your document root directory in /etc/apache2/apache2.conf. The default Ubuntu document root is /var/www/html. You can make your own virtual hosts under /var/www.
这与以前的版本不同,它提供了更好的安全性
盒子外面。
解决问题:
示例:/var/www/site
2.修复你的虚拟主机
<VirtualHost *:80>
ServerName test.local
ServerAdmin webmaster@localhost
DocumentRoot /var/www/site
<Directory "/var/www/site" >
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
关于apache - 403 错误 - Apache VirtualHost - Ubuntu 22.04,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72153484/