当我试图通过浏览器访问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>
获得问题的解决方案,需要在apache2.conf文件中进行更改,之后它将工作,
/etc/apache2/apache2.conf中的旧代码
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
改为
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
之后,为了让Apache理解重写规则,我们首先需要激活mod_rewrite。它已经安装了,但是在默认的Apache安装中禁用了它。使用a2enmod命令启用模块:
$ sudo a2enmod rewrite
这将激活模块或提醒您模块已启用。要使这些更改生效,请重新启动Apache。
$ sudo systemctl restart apache2
终于对我有用了。
如果您在windows操作系统的WampServer上使用Apache 2.4。
请在记事本中打开“http -vhosts.conf”文件。
C:\wamp64\bin\apache\apache2.4.37\conf\extra\https-vhosts.conf
如果您无法找到以上文件。查看下面的截图
<VirtualHost *:80>
ServerName localhost
DocumentRoot c:/wamp64/www
<Directory "c:/wamp64/www/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
在上述代码中替换
Require local
with
Require all granted
然后保存。重启Apache服务后重试。
如果你像我一样尝试了上面所有的答案,但都没有帮助,记得检查你的apache2.conf是否有像IncludeOptional conf-enabled/*.conf这样的行,然后检查该文件夹中的每个.conf文件。
我的有一个security.conf文件,其中包括这部分(需要删除/修改,以不阻止我需要运行的.php文件):
<FilesMatch "^(wp-config\.php|php\.ini|php5\.ini|install\.php|php\.info|readme\.md|README\.md|readme\.html|bb-config\.php|\.htaccess|\.htpasswd|readme\.txt|timthumb\.php|error_log|error\.log|PHP_errors\.log|\.sv$
Require all denied
</FilesMatch>
我不知道这个文件来自哪里,除非在某个时候我掉进了一个兔子洞,试图保护我的apache配置,找到这个conf,添加它,然后完全忘记了它。