apache - 403 错误 - Apache VirtualHost - Ubuntu 22.04

标签 apache ubuntu 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 错误。
站点/测试文件夹和文件具有 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
    示例:/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/

    相关文章:

    apache - .htaccess 中的 Require 指令阻止显示目录

    php - Nginx 错误 recv() 失败 (104 : Connection reset by peer)

    linux - 输入-PSSession 返回 PSInvalidOperationException

    php - 从我的 Linux VM 运行 PHP 应用程序时出错

    Apache 虚拟主机(子域)访问局域网上的不同计算机

    apache - 在网络上看不到网站,但在本地可以看到

    php - 当 PHP APC 缓存完全填满时,如何防止 Apache 挂起?

    apache - mod 重写不适用于 laravel 和 bitNami

    tomcat - 如何在启动时以非 root 身份启动 Tomcat

    apache2 不适用于不同端口