当我试图通过浏览器访问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>


当前回答

除了在其他答案中提到的缺少Order和Allow指令外,还要注意DirectoryMatch指令的不匹配正则表达式也可能导致此错误。

如果请求的路径是/home/user-foo1bar/www/myproject/下面的matcher将不匹配

<DirectoryMatch "/home/user-[a-z]+/www/myproject/">
...
</DirectoryMatch>

因此,即使是有效的访问配置也可能导致此错误。

其他回答

如果您有https主机,那么不要忘记使ssl配置也要求所有授予的更改。

此外,有时检查apache用户的权限也很有用:

# ps -eFH | grep http # get the username used by httpd
...
apache   18837  2692  0 119996 9328   9 10:33 ?        00:00:00     /usr/sbin/httpd -DFOREGROUND
# su -s/bin/bash apache # switch to that user
bash-4.2$ whoami
apache
bash-4.2$ cd /home
bash-4.2$ ls
bash-4.2$ cd mysite.com
bash-4.2$ ls
bash-4.2$ cat file-which-does-not-work.txt

这花了我一些摆弄,让这个工作在我自己的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>

这快把我逼疯了。终于找到了问题所在: 我在错误日志中使用了直接路径,但它们是错误的。

为什么Apache给出一个模糊的(错误的)错误消息?相反,应该使用正确且有用的错误消息,例如:Path for ErrorLog指令“/wrong/ Path /and/filename.log”是无效的。

无论如何,为了修复,确保你的错误日志指令看起来像这样:

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

确保包括任何特定于用户的配置!

如果这一页上的其他答案都不适合你,下面是我在几个小时的挣扎后遇到的。

我使用了特定于用户的配置,在/private/etc/apache2/extra/httpd-userdir.conf中将Sites指定为我的UserDir。但是,我被禁止访问端点http://localhost/~jwork/。

我可以在/var/log/apache2/error_log中看到对/Users/jwork/Sites/的访问被阻止。但是,我被允许通过http://localhost/访问DocumentRoot。这表明我没有权限查看~jwork用户。但据我所知,ps aux | egrep '(apache|httpd)'和lsof -i:80, apache是为jwork用户运行的,所以很明显没有使用我的用户配置编写一些东西。

给定一个名为jwork的用户,下面是我的配置文件:

二等兵/ etc / apache2 \用户/ jwork上。

<Directory "/Users/jwork/Sites/">
    Require all granted
</Directory>

这个配置完全有效。然而,我发现我的用户配置没有被包括在内:

/私人/ etc /输入/多/ httpd-userdir.conf

## Note how it's commented out by default.
## Just remove the comment to enable your user conf.
#Include /private/etc/apache2/users/*.conf

注意,这是userdir conf文件的默认路径,但正如您将在下面看到的,它是在httpd.conf中可配置的。确保下列行已启用:

/ / etc / apache2 /私人httpd.conf

Include /private/etc/apache2/extra/httpd-userdir.conf

# ...

LoadModule userdir_module libexec/apache2/mod_userdir.so

在花了几个小时后,我自己决定了。

我在vagrant vm中通过cookbook安装Apache/2.4.7 (Ubuntu)。

/etc/apache2/apache2.conf文件默认没有<VirtualHost *:80>元素。

我做了两处改动才完成

added <VirtualHost *:80> 添加 选项索引遵循symlinks AllowOverride所有 允许从所有

最后我启动了vm..