如何阻止 Apache 响应 http 请求?
How do I stop Apache from answering a http request?
这是我最近接受采访时提出的问题。我回答说,据我所知,没有这样的方法。但我不确定。
有没有办法阻止 Apache Web 服务器响应 HTTP 请求?
我使用 PHP 作为选择的语言,如果它有所不同的话。
要更好地理解此答案,您需要了解网络 "OSI 7 Layer Networking Model"。 (此处有更多详细信息:https://en.wikipedia.org/wiki/OSI_model)
这表明 Apache 甚至会在 PHP 代码开始执行之前 "handle" 发出请求。 (Apache 在第 5、6 和 7 层运行,其中 PHP 通常在 Apache 之上运行)。
因此,PHP 代码将无法"stop" apache 响应 HTTP 请求。相反,您需要考虑完全阻止访问(防火墙 [基于软件的硬件],在第 3/4 层运行),或者您需要 apache 具有不处理请求的逻辑。
这实际上更像是一个安全问题,而不是一个编程问题。通常对于此用例,您可能希望 apache 模块在 apache 内部确定有关处理请求的决定。一些好的模块是:mod_evasive、mod_security
- Mod_Evasive:
- https://www.digitalocean.com/community/tutorials/how-to-protect-against-dos-and-ddos-with-mod_evasive-for-apache-on-centos-7
- Mod_Security
- https://geekflare.com/apache-web-server-hardening-security/#6-Mod-Security
如有任何问题,请告诉我,谢谢!
这是我最近接受采访时提出的问题。我回答说,据我所知,没有这样的方法。但我不确定。 有没有办法阻止 Apache Web 服务器响应 HTTP 请求? 我使用 PHP 作为选择的语言,如果它有所不同的话。
要更好地理解此答案,您需要了解网络 "OSI 7 Layer Networking Model"。 (此处有更多详细信息:https://en.wikipedia.org/wiki/OSI_model)
这表明 Apache 甚至会在 PHP 代码开始执行之前 "handle" 发出请求。 (Apache 在第 5、6 和 7 层运行,其中 PHP 通常在 Apache 之上运行)。
因此,PHP 代码将无法"stop" apache 响应 HTTP 请求。相反,您需要考虑完全阻止访问(防火墙 [基于软件的硬件],在第 3/4 层运行),或者您需要 apache 具有不处理请求的逻辑。
这实际上更像是一个安全问题,而不是一个编程问题。通常对于此用例,您可能希望 apache 模块在 apache 内部确定有关处理请求的决定。一些好的模块是:mod_evasive、mod_security
- Mod_Evasive:
- https://www.digitalocean.com/community/tutorials/how-to-protect-against-dos-and-ddos-with-mod_evasive-for-apache-on-centos-7
- Mod_Security
- https://geekflare.com/apache-web-server-hardening-security/#6-Mod-Security
如有任何问题,请告诉我,谢谢!