繁体   English   中英

适用于mod_php或PHP的Apache2 API(或另一个Web服务器)

[英]Apache2 API (or another webserver) for mod_php or PHP

我正在寻找一种使用API​​来操纵运行PHP的网络服务器的方法。

例如,我希望能够动态添加mod重写规则或阻止某些路径的IP地址,而无需触摸.htaccess文件。

PHP是否存在类似这样的内容

尽管您已指出可以使用PHP编辑配置或.htaccess文件重新加载配置,但PHP不可能动态更改Apache的配置。 但是我认为,这给Web应用程序提供了比Web服务器更多的功能的巨大安全风险。

您可以使用mod_rewrite的RewriteMap指令来动态阻止IP的示例。 基本上,您将为您的网站编写一个mod_rewrite规则,该规则将指示mod_rewrite查看您的PHP脚本可以维护的外部数据源。

mod_rewrite文档提供了一个示例,从以下示例开始: 拒绝黑名单中的主机

Description:
We wish to maintain a blacklist of hosts, rather like hosts.deny,
and have those hosts blocked from accessing our server.

Solution:
RewriteEngine on
RewriteMap hosts-deny txt:/path/to/hosts.deny
RewriteCond ${hosts-deny:%{REMOTE_ADDR}|NOT-FOUND} !=NOT-FOUND [OR]
RewriteCond ${hosts-deny:%{REMOTE_HOST}|NOT-FOUND} !=NOT-FOUND
RewriteRule ^ - [F]
##
## hosts.deny
##
## ATTENTION! This is a map, not a list, even when we treat it as such.
## mod_rewrite parses it for key/value pairs, so at least a
## dummy value "-" must be present for each entry.
##

193.102.180.41 -
bsdti1.sdm.de -
192.76.162.40 -

Discussion:
The second RewriteCond assumes that you have HostNameLookups turned on,
so that client IP addresses will be resolved. If that's not the case,
you should drop the second RewriteCond, and drop the [OR] flag from
the first RewriteCond.

您的PHP脚本可以维护那些文本文件(也可以使用其他数据存储),并且可以根据您的特定需求制作任意数量的规则集来动态控制访问。 那行得通吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM