如何在 Ubuntu 上更改灯的根目录

Posted

技术标签:

【中文标题】如何在 Ubuntu 上更改灯的根目录【英文标题】:How to change root directory for lamp on Ubuntu 【发布时间】:2021-12-31 10:45:45 【问题描述】:

我正在尝试在 Ubuntu 上更改新灯泡的根目录,但是当我打开 localhost 或 127.0.0.1 时出现错误消息:**Forbidden

您无权访问此资源。**

我在 127.0.0.1 端口 80 上使用 Apache/2.4.46 (Ubuntu) 服务器和 Ubuntu 21.04。

我已经更改了 apache2.conf 和 000-default.conf :

000-default.conf:

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /home/matt/phpRoot
        ServerName 127.0.0.1


        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog $APACHE_LOG_DIR/error.log
        CustomLog $APACHE_LOG_DIR/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

还有 apache2.conf :

<Directory />
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory "/home/matt/phpRoot">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

#<Directory /srv/>
#       Options Indexes FollowSymLinks
#       AllowOverride None
#       Require all granted
#</Directory>

【问题讨论】:

将您的 LogLevel 用于调试,甚至 trace8 以在您的日志中查看更多详细信息。除了允许 Apache 访问 /home/matt/phpRoot 之外,运行 Apache 实例的用户还必须在 linux 级别访问该目录。配置权限(和 SELinux,如果已启用)。最后,在您的 VirtualHost 中添加 ServerAlias localhost 【参考方案1】:

在 000-default.conf 和 apache2.conf 中

/home/matt/phpRoot 更改为 /var/www

【讨论】:

以上是关于如何在 Ubuntu 上更改灯的根目录的主要内容,如果未能解决你的问题,请参考以下文章

Ubuntu上更改MySQL数据库数据存储目录

Ubuntu 上更改 MySQL 数据库数据存储目录

不确定如何更改根目录以远离我的 HTTP 站点内容

FileSystemWatcher不会使用'mv'命令检测移动到目录中的文件,也不会在ubuntu上剪切和粘贴

Ubuntu 更改 MySQL 数据库数据存储目录

ubuntu 更改文件夹拥有者和权限