问题介绍

403是Web服务器返回的一种非常常见的错误代码,Http协议中对403错误定义如下,

403 Forbidden

The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. If the server does not wish to make this information available to the client, the status code 404 (Not Found) can be used instead.

而在IIS中根据具体的功能对403错误通过子错误代码的形式进行了更详细的分类。

IIS 7.0 defines the following HTTP status codes that indicate a more specific cause of a 403 error:

403.1 - Execute access forbidden.

403.2 - Read access forbidden.

403.3 - Write access forbidden.

403.4 - SSL required.

403.5 - SSL 128 required.

403.6 - IP address rejected.

403.7 - Client certificate required.

403.8 - Site access denied.

403.9 - Forbidden: Too many clients are trying to connect to the Web server.

403.10 - Forbidden: Web server is configured to deny Execute access.

403.11 - Forbidden: Password has been changed.

403.12 - Mapper denied access.

403.13 - Client certificate revoked.

403.14 - Directory listing denied.

403.15 - Forbidden: Client access licenses have exceeded limits on the Web server.

403.16 - Client certificate is untrusted or invalid.

403.17 - Client certificate has expired or is not yet valid.

403.18 - Cannot execute requested URL in the current application pool.

403.19 - Cannot execute CGI applications for the client in this application pool.

403.20 - Forbidden: Passport logon failed.

403.21 - Forbidden: Source access denied.

403.22 - Forbidden: Infinite depth is denied.

403.502 - Forbidden: Too many requests from the same client IP; Dynamic IP Restriction limit reached.

这篇文章通过实验来重现一些常见的403错误,希望能够更加形象的演示各种错误发生的原因,并介绍相应问题的解决方法。

[403.1 403.3]

造成403.1 - 403.3的主要原因是由于handler需要的权限受到Handler Mapping中启用的权限的限制。

483922da6b939591167ebe356e42afdb.png

如何查看handler需要的权限?可以通过IIS Manager - Handler Mapping,根据请求的扩展名找到相应的Handler,比如我们请求.asp文件的时候报错403.3,找到处理.asp文件的handler为ASPClassic这个handler,双击打开这个handler的Script Map - Request Restrictions - Access,可以查看该handler需要的权限。在这里为了重现403.3问题,我将需要权限设置为write。

c63c33943cce0847b58ea3c7f37233ac.png

如何查看Handler Mapping启用的权限?可以通过IIS Manager - Configuration Editor打开system.webServer/handlers@accesspolicy配置节点如下,可以看到Write选项没有被选中,所以在访问asp页面的时候会出现403.3错误。另外在handler mapping中也可以看到相应的ASPClassic handler对应的状态为disabled。

f4da5356fb13a3e3007301c10c2678ff.png

403.1, 403.2的错误原因与403.3是一致的,即相应handler需要的的Script或者Read权限没有启用。

[403.4 403.5 403.7]

403.4, 403.5, 403.7均是由于SSL设置造成的,本身大多数时候并非服务器端错误,而是客户端的请求没有满足服务端的要求。例如

403.4是指客户端发送了一个http请求到一个配置了需要SSL的网站

403.5是指客户端发送的请求没有满足服务器对于SSL的加密位数要求

403.7是指客户端没有提供相应的证书

这些配置可以通过服务器端IIS Manager - SSL Setting中来配置,

e0a43032e83fc34d97e0b30e6c1b7b8a.png

但是对于ssl的128位数要求需要通过Configuration Editor来找到system.webServer/security/access@sslFlags来配置

9e0cb5a32017f8dd27b1903a2c70629e.png

对于403.7错误有一个值得注意的地方,服务器如果配置了需要客户端证书,客户端正常情况下会弹出证书选择框来给用户选择用哪个证书发送给服务器。如果客户端在只有一张证书的情况下不会弹选择框而直接发送给服务器。如果遇到了403.7错误,很可能是因为客户端没有找到一个可用的证书。

97a79b7edf1db2c28706ee7146b4ed03.png

这里所谓的可用证书的根据服务器返回的信任列表来定义的,根据SSL协议,服务器会在SSL握手的时候返回一组服务器信任的根证书给客户端,客户端查找是否存在相应的用户证书链接自这些根证书,然后弹出选择框。所以如果这里没有找到客户端证书的话,要先确定客户端是否有相应的证书,如果没有则需要安装,如果证书存在,那么要检查其相应的根证书是否在服务器端的信任列表中。

[403.14]

403.14非常常见,而且原因也很简单,就是目录不允许被浏览。

36b43377d8c6fb8532729bbeb8bc93a6.png

解决方法要根据实际需求来看,

1. 如果客户请求的问题,即浏览了不该浏览的目录,那服务器不需要任何更改

2. 如果浏览的目录期待的结果应该是一个默认网页,很有可能是default document没有配好或者不在目录下

3. 如果需要启用目录浏览,则到IIS Manager到指定的目录 - Directory Browsing - Enable

[403.6 403.8]

这两种错误与服务器配置相关,服务器在ipSecurity配置中阻止了客户端相应的ip或者dns名字。具体的配置为system.webServer/security/ipSecurity

322e38db7629791b02c79c86c8263060.png

以上就是最常见的403错误以及相应的解决方法,如果遇到了一些比较少见的其他错误,可以参考这里查找具体的解决方案。

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐