【问题标题】:Httpd only allows to access files that are directly created in the /var/www/html folderHttpd 只允许访问直接在 /var/www/html 文件夹中创建的文件
【发布时间】:2020-01-12 01:17:25
【问题描述】:

我第一次使用 Httpd,最终目标是在本地 RHEL 服务器(没有外部互联网访问)上设置一个 wordpress 实例。
所以我通过yum 安装了httpd,并在/var/www/html 文件夹中使用了touch hello.html,该文件夹运行良好,并且可以通过浏览器访问该文件。现在我开始通过winScp将另一台计算机的html文件移动到服务器的根目录,并用mv将它移动到文件夹中。我也确实使用了chmod 来设置正确的访问权限,但它没有用。

如何设置服务器来提供这些文件? Atm 我收到 403 Forbidden 错误,所以我假设我必须在 httpd 配置中做一些事情?

非常感谢您为我提供帮助!

【问题讨论】:

  • 将从哪个目录提供网页?
  • 它们应该从根文件夹提供,例如 http:///hello.html
  • http:///hello.html 并不表示页面从哪里提供。这是我要问的文档根目录。通常 apache 提供来自/var/www 的页面。您打算从哪里提供网页?
  • 对不起,我错过了你的观点。据我所知 /var/www/html 文件夹中的文件?我在那个文件夹中直接接触的所有文件也直接在我提到的 IP 下提供

标签: wordpress apache httpd.conf rhel7


【解决方案1】:

最好使用VirtualHost,并将配置放在启用站点的目录中。你当然可以编辑你的 httpd.conf 并将配置放在那里。只是管理不够灵活。

使用sudo编辑/etc/httpd/conf/httpd.conf

在 httpd.conf 的末尾添加IncludeOptional sites-enabled/*.conf。保存并退出。

sudo mkdir /etc/httpd/sites-enabled /etc/httpd/sites-available

使用sudo,编辑/etc/httpd/sites-available/mysite.conf and add the followingVirtualHosts` 块:

<VirtualHost *:80>
    DocumentRoot /var/www/html
    ServerName mysite.domain
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

现在创建指向启用站点的目录的配置链接

sudo ln -s /etc/httpd/sites-available/mysite.conf /etc/http/sites-enabled

要在完成上述操作后重新启动 Apache,请执行以下操作

sudo systemctl restart httpd

另一种方法是直接在httpd.conf中添加VirtualHost块,然后重新启动Apache。

【讨论】:

    猜你喜欢
    • 2020-12-08
    • 2018-11-27
    • 1970-01-01
    • 2017-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多