我们来看俩段通常对上传目录设定无许可权的例子, 配置如下:
程式码如下:
Order Allow,Deny
Deny from all
这些配置表面上看起来是没什么问题的,确实在 windows 下可以这么说。
但是 linux 就不同了,大家都是知道的 linux 操作系统是区分大小写的,这里如果换成大写字尾名*.phP 一类就 pass 了
这里我说下我个人的解决方法,程式码如下:
ErrorDocument 404 /404/404.html
ErrorDocument 403 /404/403.html
// ? 是尽可能多的匹配.php 的字串,i 是不区分大小写, 然后冒号后面跟上正规表示式,
也可以写成:
Order allow,deny
Deny from all
上面的意思就是说,
另外一种方法,是设定在 htaccess 里面的,这个方法比较灵活一点,针对那些没有 apapche 安全操作许可权的网站管理员:
Apache 环境规则内容如下:Apache 执行 php 指令码限制 把这些规则新增到.htaccess 档案中
程式码如下:
RewriteEngine on RewriteCond % !^$
RewriteRule uploads/(.*).(php)$ – [F]
RewriteRule data/(.*).(php)$ – [F]
RewriteRule templets/(.*).(php)$ –[F]
另外一种方法,程式码如下:
php_admin_flag engine off
此方法我在 win 系统下面测试失败了,重新启动 apapche 出现下面的错误资讯:
The Apache service named reported the following error:
>>> Invalid command ‘php_flag’, perhaps misspelled or defined by a module not included in the server configuration.
这里我就不具体说明这个解决办法了,因为禁止 php 执行的方法,大家看自己的需求去设定就可以了!
【apache 配置禁止访问】
1. 禁止访问某些档案/目录
增加 Files 选项来控制,比如要不允许访问 .inc 副档名的档案,保护 php 类库:
Order allow,deny
Deny from all
禁止访问某些指定的目录:(可以用
Order allow,deny
Deny from all
通过档案匹配来进行禁止,比如禁止所有针对图片的访问:
Order allow,deny
Deny from all
针对 URL 相对路径的禁止访问:
Order allow,deny
Deny from all
针对代理方式禁止对某些目标的访问(
Order allow,deny
Deny from all
2. 禁止某些 IP 访问/只允许某些 IP 访问
如果要控制禁止某些非法 IP 访问,在 Directory 选项控制:
Order allow,deny
Allow from all
Deny from 10.0.0.1 #阻止一个 IP
Deny from 192.168.0.0/24 #阻止一个 IP 段
只允许某些 IP 访问,适合比如就允许内部或者合作公司访问:
Order deny,allow
Deny from all
All from example.com #允许某个域名
All from 10.0.0.1 #允许一个 iP
All from 10.0.0.1 10.0.0.2 #允许多个 iP
Allow from 10.1.0.0/255.255.0.0 #允许一个 IP 段,掩码对
All from 10.0.1 192.168 #允许一个 IP 段,后面不填写
All from 192.168.0.0/24 #允许一个 IP 段,互联网号
Apache:解决办法;
Options -Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Deny from all