[英]403 Error - Apache VirtualHost - Ubuntu 22.04
i recently install ubuntu 22.04 and try to use LAMP on it.我最近安装了 ubuntu 22.04 并尝试在其上使用 LAMP。 but i have problem with VirtualHost.但我对 VirtualHost 有疑问。 i want use virtualhosts with a local domain like: test.local i added this domain to /etc/hosts and add this configuration to my test.local.conf:我想将虚拟主机与本地域一起使用,例如: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>
and then run: a2ensite test.local.conf but when i open test.local in my browser, apache show me a 403 error.然后运行:a2ensite test.local.conf 但是当我在浏览器中打开 test.local 时,apache 显示 403 错误。 Sites/test folder and files have 0777 permission and owner is my username.站点/测试文件夹和文件具有 0777 权限,所有者是我的用户名。 what i should to do for fix this problem?我应该怎么做才能解决这个问题?
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).默认情况下,Ubuntu 不允许通过 web 浏览器访问位于 /var/www、public_html 目录(启用时)和 /usr/share(对于 web 应用程序)中的文件以外的任何文件。 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.如果您的站点使用位于其他位置(例如 /srv 中)的 web 文档根目录,您可能需要在 /etc/apache2/apache2.conf 中将文档根目录列入白名单。 The default Ubuntu document root is /var/www/html.默认的 Ubuntu 文档根目录是 /var/www/html。 You can make your own virtual hosts under /var/www.您可以在 /var/www 下创建自己的虚拟主机。
This is different to previous releases which provides better security out of the box.这与以前的版本不同,后者提供更好的开箱即用安全性。
To solve the problem:解决问题:
Move your source code to /var/www将您的源代码移动到 /var/www
Example: /var/www/site示例:/var/www/网站
2.Fix your Virtualhost 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>
Add your user to the apache group then it's working fine将您的用户添加到 apache 组然后它工作正常
sudo usermod -g www-data <YOUR_USERNAME>
my soluttion was a downgrade to 20.04;) sorry if I can't give you a better solution.我的解决方案是降级到 20.04;)抱歉,如果我不能给你更好的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.