当我试图通过浏览器访问localhost时,我得到这个错误。

AH01630: client denied by server configuration

我检查了我的网站文件夹权限使用:

sudo chmod 777 -R *

这是我的配置文件:

<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /home/user-name/www/myproject
<Directory />
    Options FollowSymLinks
    AllowOverride all
    Allow from all
</Directory>

<Location />
  Allow from all
  Order Deny,Allow
</Location>

<Directory  /home/user-name/www/myproject/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order allow,deny
    Allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride all
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride all
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>


当前回答

我在新服务器上设置虚拟主机时遇到了这个问题,并且站点托管在标准的/var/www/html路径之外。您需要考虑两件主要的事情(例如,假设您正在/opt/my-site中设置一个站点)

在默认的2.4安装中,会显式地拒绝访问根文件系统,然后只允许访问/var/www/html。所以你需要给web服务器从新目录读取的权限,就像这样:

<Directory /opt/mysite>
   Require all granted
</Directory>

完成此操作后,请确保虚拟主机的DocumentRoot位于上面授予访问权限的路径下的某个位置。

<VirtualHost *:80>
        ServerName neatwebsite.com
        DocumentRoot /opt/my-site/html
</VirtualHost>

当我遇到这个问题时,我已经设置好了所有的VirtualHosts,但忘记允许从目录结构中读取(所以我错过了指令)。您需要考虑这两个指令,以及它们如何协同工作。

其他回答

对我来说,所有提出的解决方案都行不通。这可以帮助,如果你使用cgi, fastcig或fpm作为代理,你必须在你的vhost中添加一个位置来避免这个问题。这允许404是传递代理。

<Location />
require all granted
</Location>

有没有人想过wamp服务器默认不包括httpd-vhosts.conf文件。 我的方法是删除下面的注释

 conf
  # Virtual hosts
  Include conf/extra/httpd-vhosts.conf

在httpd.conf文件中。 仅此而已。

对于所有目录,写入“要求所有授予”,而不是“允许从所有”

更新

如果上面的不工作,然后也删除下面提到的行:

为了允许,拒绝

再次检查DocumentRoot路径是否正确。这可能会导致此错误。

这花了我一些摆弄,让这个工作在我自己的FreeBSD服务器运行..

FreeBSD 13 Apache 2.4 Python 3.8 LetsEncrypt

. .但最终我想出了一个可行的VirtualHost:

<VirtualHost *:443>

    ServerName mysite.mydomain.com
    DocumentRoot "/usr/local/www/apache24/data/mysite

    WSGIDaemonProcess mysite python-path=/usr/local/www/apache24/data/mysite/venv/lib/python3.8/site-packages/
    WSGIProcessGroup mysite
    WSGIScriptAlias / /usr/local/www/apache24/data/mysite/core/wsgi.py

    SSLEngine on
    SSLCertificateFile "/usr/local/etc/letsencrypt/live/mysite.mydomain.com/cert.pem"
    SSLCertificateKeyFile "/usr/local/etc/letsencrypt/live/mysite.mydomain.com/privkey.pem"
    SSLCertificateChainFile "/usr/local/etc/letsencrypt/live/mysite.mydomain.com/fullchain.pem"

    <FilesMatch "\.(cgi|shtml|phtml|php|py)$">
        SSLOptions +StdEnvVars
    </FilesMatch>

    BrowserMatch "MSIE [2-5]" \
        nokeepalive ssl-unclean-shutdown \
        downgrade-1.0 force-response-1.0

    CustomLog "/usr/local/www/apache24/data/mysite/log/py-ssl.log" \
        "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    CustomLog "/usr/local/www/apache24/data/mysite/log/py-access.log" combined
    ErrorLog "/usr/local/www/apache24/data/mysite/log/py-error.log"

    <Directory "/usr/local/www/apache24/data/mysite">
        AllowOverride All
        Options +ExecCGI
        Require all granted
        Allow from all
    </Directory

</VirtualHost>