我已经在远程服务器上设置了 Apache。
以下是文件的内容/etc/apache2/sites-available/example.com.conf
:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
ServerAlias images.example.com
DocumentRoot /home/myUserName/var/www/example.com/public_html/
ErrorLog /home/myUserName/var/www/example.com/logs/error.log
CustomLog /home/myUserName/var/www/example.com/logs/access.log combined
</VirtualHost>
我已经为我的托管服务提供商设置了正确的“A”和“AAAA”记录。但是当我访问时http://images.example.com
,出现了 403 错误。
Forbidden
You don't have permission to access / on this server.
Apache/2.4.7 (Ubuntu) Server at images.example.com Port 80
我该如何设置才能http://images.example.com
让我看到的内容/home/myUserName/var/www/example.com/public_html/
?
更新
内容error.log
:
[Sun May 20 21:37:05.305775 2018] [authz_core:error] [pid 4858] [client 2601:587:5:6a70:428d:5cff:fe71:b1e4:56518] AH01630: client denied by server configuration: /home/myUserName/var/www/example.com/public_html/
[Sun May 20 21:41:15.517163 2018] [authz_core:error] [pid 4859] [client 51.38.12.23:42405] AH01630: client denied by server configuration: /home/myUserName/var/www/example.com/public_html/
[Sun May 20 21:43:49.090780 2018] [authz_core:error] [pid 4860] [client 2601:587:5:6a70:428d:5cff:fe71:b1e4:56678] AH01630: client denied by server configuration: /home/myUserName/var/www/example.com/public_html/
[Sun May 20 21:48:59.756624 2018] [authz_core:error] [pid 4861] [client 179.127.179.39:43803] AH01630: client denied by server configuration: /home/myUserName/var/www/example.com/public_html/
[Sun May 20 21:53:22.709395 2018] [authz_core:error] [pid 4864] [client 178.73.215.171:28502] AH01630: client denied by server configuration: /home/myUserName/var/www/example.com/public_html/
运行ls -la /home/myUserName/var/www/example.com/public_html/
输出如下:
total 12
drwxrwxr-x 3 myUserName myUserName 4096 May 20 22:58 .
drwxrwxr-x 4 myUserName myUserName 4096 May 20 21:32 ..
drwxr-xr-x 13 myUserName myUserName 4096 Apr 14 02:18 tile
答案1
首先验证文件的基本访问是否有效,方法是将文件放入该目录中并通过正确的 URL 直接访问它。请求目录/路径要么打开相应的 DirectoryIndex 文件,要么给出 403(如果没有),这会增加混乱。
关于您的问题。如果我理解正确,打开 / 应该显示该目录的内容,那么可以通过在 php 等中编写自定义列表脚本来实现,或者只需通过启用和调整 Apache 的设置来mod_autoindex
实现。Options +Indexes
答案2
应该有一个目录和允许访问的选项,但出现 403 错误,我认为在目录 home 中没有 index.html、index.php 之类的文件,也可能意味着您没有设置“要求全部授予”选项。例如:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
ServerAlias images.example.com
DocumentRoot "/home/myUserName/var/www/example.com/public_html/"
ErrorLog /home/myUserName/var/www/example.com/logs/error.log
CustomLog /home/myUserName/var/www/example.com/logs/access.log combined
<Directory "/home/myUserName/var/www/example.com/public_html">
Options -Indexes +FollowSymLinks
DirectoryIndex index.html index.php
Require all granted
</Directory>
<VirtualHost *:80>
要查看目录的内容,请将 -Indexes 更改为 +Indexes