403 错误 - Apache VirtualHost - Ubuntu 22.04
403 Error - Apache VirtualHost - Ubuntu 22.04
我最近安装了 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 错误。
Sites/test 文件夹和文件有 0777 权限,所有者是我的用户名。
我应该怎么做才能解决这个问题?
我的解决方案是降级到 20.04 ;) 如果我不能给你更好的解决方案,我很抱歉。
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
示例:/var/www/站点
2.Fix 你的虚拟主机
<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>
我最近安装了 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 错误。 Sites/test 文件夹和文件有 0777 权限,所有者是我的用户名。 我应该怎么做才能解决这个问题?
我的解决方案是降级到 20.04 ;) 如果我不能给你更好的解决方案,我很抱歉。
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
示例:/var/www/站点
2.Fix 你的虚拟主机
<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>