httpd 只允许访问直接在 /var/www/html 文件夹中创建的文件
Httpd only allows to access files that are directly created in the /var/www/html folder
我是第一次使用 Httpd,最终目标是在本地 RHEL 服务器(没有外部互联网访问权限)上设置一个 wordpress 实例。
因此,我通过 yum
安装了 httpd,并在 /var/www/html
文件夹中使用了 touch hello.html
,效果很好,并且可以通过浏览器访问该文件。现在我开始通过winScp
从另一台计算机移动一个html文件到服务器的根目录,并用mv
移动到文件夹。我也确实使用 chmod
来设置正确的访问权限,但它没有用。
如何设置服务器来提供这些文件? Atm 我收到一个 403 Forbidden
错误,所以我假设我必须在 httpd 配置中做一些事情?
如果能帮助我加入,我将不胜感激!
最好使用 VirtualHost
,并将配置放在 sites-enabled 目录中。您当然可以只编辑 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 following
VirtualHosts` 块:
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName mysite.domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
现在为启用站点的目录
的配置创建 link
sudo ln -s /etc/httpd/sites-available/mysite.conf /etc/http/sites-enabled
要在完成上述操作后重新启动 Apache,请执行
sudo systemctl restart httpd
另一种方法是直接在 httpd.conf
中添加 VirtualHost 块,然后重新启动 Apache。
我是第一次使用 Httpd,最终目标是在本地 RHEL 服务器(没有外部互联网访问权限)上设置一个 wordpress 实例。
因此,我通过 yum
安装了 httpd,并在 /var/www/html
文件夹中使用了 touch hello.html
,效果很好,并且可以通过浏览器访问该文件。现在我开始通过winScp
从另一台计算机移动一个html文件到服务器的根目录,并用mv
移动到文件夹。我也确实使用 chmod
来设置正确的访问权限,但它没有用。
如何设置服务器来提供这些文件? Atm 我收到一个 403 Forbidden
错误,所以我假设我必须在 httpd 配置中做一些事情?
如果能帮助我加入,我将不胜感激!
最好使用 VirtualHost
,并将配置放在 sites-enabled 目录中。您当然可以只编辑 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 following
VirtualHosts` 块:
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName mysite.domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
现在为启用站点的目录
的配置创建 linksudo ln -s /etc/httpd/sites-available/mysite.conf /etc/http/sites-enabled
要在完成上述操作后重新启动 Apache,请执行
sudo systemctl restart httpd
另一种方法是直接在 httpd.conf
中添加 VirtualHost 块,然后重新启动 Apache。