Apache2:'AH01630:服务器配置拒绝客户端'

本文详细解析了在尝试通过浏览器访问localhost时遇到的Apache2 'AH01630:client denied by server configuration' 错误。提供了检查站点文件夹权限的方法,分析了配置文件设置,并给出了针对Apache2.4版本的解决方案,包括修改允许和拒绝规则,更新Require指令,以及确保DocumentRoot路径正确。

本文翻译自:Apache2: 'AH01630: client denied by server configuration'

I get this error when trying to access localhost via a browser. 尝试通过浏览器访问localhost时出现此错误。

AH01630: client denied by server configuration

I checked my site folder permissions using: 我使用以下方法检查了站点文件夹权限:

sudo chmod 777 -R *

Here is my configuration file: 这是我的配置文件:

<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>


#1楼

参考:https://stackoom.com/question/1FAn7/Apache-AH-服务器配置拒绝客户端


#2楼

If you tail the error log and reload the page, you should see some more information as to the exact problem. 如果拖尾错误日志并重新加载页面,则应该看到有关确切问题的更多信息。

Grab the environment variables so ${APACHE_LOG_DIR} will actually work... 抓住环境变量,以便$ {APACHE_LOG_DIR}实际上可以工作...

source /etc/apache2/envvars

Then tail and watch... 然后尾巴看...

tail -f ${APACHE_LOG_DIR}/error.log

#3楼

If you are using Apache 2.4 如果您使用的是Apache 2.4

You have to check allow and deny rules 您必须检查允许和拒绝规则

Check out http://httpd.apache.org/docs/2.4/upgrading.html#access 查看http://httpd.apache.org/docs/2.4/upgrading.html#access

In 2.2, access control based on client hostname, IP address, and other characteristics of client requests was done using the directives Order, Allow, Deny, and Satisfy. 在2.2中,使用指令Order,Allow,Deny和Satisfy完成了基于客户机主机名,IP地址和客户机请求其他特征的访问控制。

In 2.4, such access control is done in the same way as other authorization checks, using the new module mod_authz_host. 在2.4中,使用新模块mod_authz_host以与其他授权检查相同的方式完成这种访问控制。

The new directive is Require : 新指令为Require

2.2 configuration: 2.2配置:

Order allow,deny
Allow from all

2.4 configuration: 2.4配置:

Require all granted

Also don't forget to restart the apache server after these changes ( # service httpd restart ) 也不要忘记在这些更改后重新启动apache服务器( # service httpd restart


#4楼

Double check that the DocumentRoot path is correct. 仔细检查DocumentRoot路径是否正确。 That can cause this error. 那会导致这个错误。


#5楼

For all directories write Require all granted instead of Allow from all 对于所有目录,请写Require all granted而不是Allow from all 就像是

Update 更新资料

If the above doesn't work then also remove this below mentioned line: 如果上述方法不起作用,则还要删除下面提到的这一行:

Order allow,deny 订单允许,拒绝


#6楼

I made the same changes that ravisorg suggested to OSX 10.10 Yosemite that upgrades Apache to version 2.4. 我做了与ravisorg建议的OSX 10.10 Yosemite相同的更改,将Apache升级到了版本2.4。 Below are the changes that were added to http.conf. 以下是添加到http.conf中的更改。

<Directory />
    AllowOverride none
    Require all denied
</Directory>

<Directory /Volumes/Data/Data/USER/Sites/>
    AllowOverride none
    Require all granted
</Directory>
[Sun Jun 29 14:55:13.531112 2025] [core:error] [pid 27208:tid 1168] [client ::1:61472] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use &#39;LimitInternalRecursion&#39; to increase the limit if necessary. Use &#39;LogLevel debug&#39; to get a backtrace. [Sun Jun 29 14:56:16.227311 2025] [core:error] [pid 27208:tid 1148] [client ::1:61485] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use &#39;LimitInternalRecursion&#39; to increase the limit if necessary. Use &#39;LogLevel debug&#39; to get a backtrace. [Sun Jun 29 15:04:18.703894 2025] [core:warn] [pid 35516:tid 364] AH00098: pid file C:/xampp/apache/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run? [Sun Jun 29 15:04:18.862470 2025] [mpm_winnt:notice] [pid 35516:tid 364] AH00455: Apache/2.4.58 (Win64) OpenSSL/3.1.3 PHP/8.2.12 configured -- resuming normal operations [Sun Jun 29 15:04:18.862470 2025] [mpm_winnt:notice] [pid 35516:tid 364] AH00456: Apache Lounge VS17 Server built: Oct 18 2023 13:03:18 [Sun Jun 29 15:04:18.862470 2025] [core:notice] [pid 35516:tid 364] AH00094: Command line: &#39;c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache&#39; [Sun Jun 29 15:04:18.873441 2025] [mpm_winnt:notice] [pid 35516:tid 364] AH00418: Parent: Created child process 37656 [Sun Jun 29 15:04:21.226512 2025] [mpm_winnt:notice] [pid 37656:tid 320] AH00354: Child: Starting 64 worker threads. [Sun Jun 29 15:07:19.452902 2025] [core:warn] [pid 29396:tid 396] AH00098: pid file C:/xampp/apache/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run? [Sun Jun 29 15:07:19.567596 2025] [mpm_winnt:notice] [pid 29396:tid 396] AH00455: Apache/2.4.58 (Win64) OpenSSL/3.1.3 PHP/8.2.12 configured -- resuming normal operations [Sun Jun 29 15:07:19.567596 2025] [mpm_winnt:notice] [pid 29396:tid 396] AH00456: Apache Lounge VS17 Server built: Oct 18 2023 13:03:18 [Sun Jun 29 15:07:19.567596 2025] [core:notice] [pid 29396:tid 396] AH00094: Command line: &#39;c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache&#39; [Sun Jun 29 15:07:19.579564 2025] [mpm_winnt:notice] [pid 29396:tid 396] AH00418: Parent: Created child process 37736 [Sun Jun 29 15:07:21.852612 2025] [mpm_winnt:notice] [pid 37736:tid 332] AH00354: Child: Starting 64 worker threads. [Sun Jun 29 15:07:32.462402 2025] [core:error] [pid 37736:tid 1180] [client ::1:61597] AH00126: Invalid URI in request &#39;index.php&#39; &#39;GET /web/UserLogin/accountLogin HTTP/1.1&#39; [Sun Jun 29 15:07:50.674094 2025] [core:error] [pid 37736:tid 1176] [client ::1:61598] AH00126: Invalid URI in request &#39;index.php&#39; &#39;GET /web/UserLogin/accountLogin HTTP/1.1&#39; [Sun Jun 29 15:08:28.424576 2025] [core:warn] [pid 25176:tid 336] AH00098: pid file C:/xampp/apache/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run? [Sun Jun 29 15:08:28.539271 2025] [mpm_winnt:notice] [pid 25176:tid 336] AH00455: Apache/2.4.58 (Win64) OpenSSL/3.1.3 PHP/8.2.12 configured -- resuming normal operations [Sun Jun 29 15:08:28.539271 2025] [mpm_winnt:notice] [pid 25176:tid 336] AH00456: Apache Lounge VS17 Server built: Oct 18 2023 13:03:18 [Sun Jun 29 15:08:28.539271 2025] [core:notice] [pid 25176:tid 336] AH00094: Command line: &#39;c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache&#39; [Sun Jun 29 15:08:28.574179 2025] [mpm_winnt:notice] [pid 25176:tid 336] AH00418: Parent: Created child process 12320 [Sun Jun 29 15:08:30.762870 2025] [mpm_winnt:notice] [pid 12320:tid 352] AH00354: Child: Starting 64 worker threads. [Sun Jun 29 15:09:23.908308 2025] [core:error] [pid 12320:tid 1184] [client ::1:61618] AH00126: Invalid URI in request &#39;index.php&#39; &#39;GET /web/Index/thinkPHP8 HTTP/1.1&#39;
06-30
<think>我们正在解决ApacheAH00124错误(内部重定向超出限制)和AH00126错误(无效URI请求)。根据引用[4],LimitInternalRecursion用于防止因配置错误导致的无限重定向循环。用户的问题集中在如何解决这两个错误。首先,我们分析AH00124错误:此错误通常由重写规则循环引起。Apache默认限制10次内部重定向,超过则报错。解决方案包括:1.调整LimitInternalRecursion指令(临时解决,但应先修复根本问题)2.修复重写规则配置错误(根本解决方案)其次,AH00126错误通常与无效URI请求有关,可能是URI格式不正确或包含非法字符。结合用户提供的引用和问题,我们分步骤解决:步骤1:诊断重写规则循环(针对AH00124)-启用重写日志(如引用[1]中的方法,但实际需要修改Apache配置)-在虚拟主机配置中添加:```apacheLogLevelalert rewrite:trace6```-重启Apache后重现问题,查看错误日志,找到循环的重写规则。步骤2:修复重写规则常见问题及修复(参考之前的回答和引用):-缺少终止标志[L]:确保在重定向到前端控制器(如index.php)后使用[L]标志。-未排除真实文件和目录:在重写条件中检查文件(!-f)和目录(!-d)。-未排除入口文件本身:避免对入口文件(如index.php)再次重写。示例修复配置(针对ThinkPHP等框架):```apache<Directory "/var/www/html">RewriteEngineOn#排除真实存在的文件和目录RewriteCond %{REQUEST_FILENAME}!-fRewriteCond%{REQUEST_FILENAME} !-d#排除入口文件,避免循环RewriteCond %{REQUEST_URI} !^/index\.php#重写规则RewriteRule ^(.*)$ index.php?/$1[L,QSA]</Directory>```步骤3:处理AH00126错误(无效URI请求)此错误通常由客户端发送的非法URI引起,例如包含未编码的空格或特殊字符。解决方案:-检查应用程序中生成URL的代码,确保正确编码。-在Apache配置中,使用CheckSpelling指令(谨慎使用)或重写规则规范化URI。-如果问题由客户端发送,可忽略(但需确保服务器不崩溃)。步骤4:调整LimitInternalRecursion(临时方案)如果确认循环无法立即修复,可增加限制(但这不是根本解决办法):```apacheLimitInternalRecursion20```步骤5:安全加固(参考引用[2])在修复过程中,可考虑安全设置,例如禁止上传目录执行PHP:```apache<Directory "/var/www/html/uploads">php_admin_flagengine off<FilesMatch "\.php$">OrderDeny,AllowDenyfrom all</FilesMatch></Directory>```步骤6:验证与测试-运行配置测试:`apachectlconfigtest`-使用curl测试重定向:`curl-ILhttp://localhost/path`最后,根据引用[3]的虚拟主机配置示例,确保虚拟主机配置正确,特别是DocumentRoot和Directory指令。完整示例配置(整合解决方案):```apache<VirtualHost*:80>ServerAdmin webmaster@example.comDocumentRoot"/var/www/html"ServerNameexample.com#错误日志设置ErrorLog"logs/example_error_log"CustomLog"logs/example_access_log" common#重写日志(调试时开启,生产环境关闭)#LogLevelalert rewrite:trace6#调整重定向递归限制(可选)LimitInternalRecursion20<Directory "/var/www/html">OptionsFollowSymLinksAllowOverride AllRequireall granted#重写规则配置RewriteEngine OnRewriteBase/#排除真实文件和目录RewriteCond%{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME}!-d#排除入口文件RewriteCond %{REQUEST_URI} !^/index\.phpRewriteRule^(.*)$index.php?/$1 [L,QSA]</Directory>#禁止上传目录执行PHP<Directory"/var/www/html/uploads">php_admin_flagengine off<FilesMatch "\.php$">Require alldenied</FilesMatch></Directory> </VirtualHost> ```注意:修改配置后重启Apache。如果问题仍然存在,请提供重写日志片段以便进一步分析。相关问题:1.如何调试Apache的mod_rewrite规则?2.如何防止.htaccess配置错误导致的安全问题?3.Apache常见配置错误有哪些?</think>## 解决 Apache AH00124AH00126 错误 ### 问题原因分析 - **AH00124 错误**:请求超过默认10次内部重定向限制,通常由重写规则循环引起[^4] - **AH00126 错误**:无效URI请求,通常由特殊字符或未编码的URI导致 ### 完整解决方案 #### 1. 修复重写规则循环(AH00124) **修改虚拟主机配置**: ```apache <VirtualHost *:80> ... # 增加递归限制(临时方案) LimitInternalRecursion 20 # 修复重写规则(关键) RewriteEngine On RewriteBase / # 排除真实文件和目录 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # 排除入口文件避免循环[^2] RewriteCond %{REQUEST_URI} !^/index\.php # 添加终止标志 RewriteRule ^(.*)$ index.php?url=$1 [L,QSA] </VirtualHost> ``` #### 2. 解决无效URI请求(AH00126) **添加URI规范化规则**: ```apache # 特殊字符编码处理 RewriteRule ^[^/]+/[^/]+\.php(.*)$ /index.php?$1 [NE,R=301,L] # 防止双斜杠问题 RewriteCond %{THE_REQUEST} // RewriteRule .* /$0 [R=301,L] ``` #### 3. 安全加固配置 **禁止上传目录执行PHP**[^2]: ```apache <Directory "/var/www/uploads"> php_admin_flag engine off <FilesMatch "\.(php|phar)$"> Require all denied </FilesMatch> </Directory> ``` #### 4. 调试步骤 1. 启用详细日志: ```apache LogLevel debug RewriteLog "/var/log/apache2/rewrite.log" RewriteLogLevel 3 ``` 2. 测试配置语法: ```bash apachectl configtest ``` 3. 使用curl测试重定向链: ```bash curl -IL --path-as-is "http://localhost/problem/url with space.php" ``` #### 5. 完整配置示例 ```apache <VirtualHost *:80> ServerAdmin admin@example.com DocumentRoot "/var/www/html" ServerName www.example.com # 错误日志配置[^3] ErrorLog "logs/example_error.log" CustomLog "logs/example_access.log" combined # 重定向递归限制 LimitInternalRecursion 20 # 重写规则配置 <Directory "/var/www/html"> RewriteEngine On RewriteBase / # 排除真实资源 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/index\.php # 特殊字符处理 RewriteRule ^[^/]+/[^/]+\.php(.*)$ /index.php?$1 [NE,R=301,L] # 主重写规则 RewriteRule ^(.*)$ index.php?url=$1 [L,QSA] </Directory> # 安全配置 <Directory "/var/www/uploads"> php_admin_flag engine off <FilesMatch "\.(php|phar)$"> Require all denied </FilesMatch> </Directory> </VirtualHost> ``` ### 关键注意事项 1. **重写规则标志**:必须包含 `[L]` 终止后续规则处理 2. **条件排除**:务必排除真实文件和目录(`!-f` 和 `!-d`) 3. **特殊字符**:URI包含空格时需使用 `--path-as-is` 参数测试 4. **临时方案**:`LimitInternalRecursion` 仅作为调试手段,最终需修复规则 > **最佳实践**:修改配置后执行 `sudo systemctl reload apache2` 避免服务中断。生产环境调试完成后应关闭详细日志(`RewriteLogLevel 0`)[^3]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值