Posts Tagged ‘apache’

nginx apache 执行php脚本限制

Apache环境规则内容如下:Apache执行php脚本限制 把这些规则添加到.htaccess文件中

RewriteEngine on RewriteCond % !^$

RewriteRule uploads/(.*).(php)$ – [F]

RewriteRule data/(.*).(php)$ – [F]

RewriteRule templets/(.*).(php)$ –[F]

nginx环境规则内容如下:nginx执行php脚本限制

LNMP有一个缺点就是目录权限设置上不如Apache,有时候网站程序存在上传漏洞或类似pathinfo的漏洞从而导致被上传了php木马,而给网站和服务器带来比较大危险。建议将网站目录的PHP权限去掉,当访问上传目录下的php文件时就会返回403错误。

首先要编辑nginx的虚拟主机配置,在fastcgi的location语句的前面按下面的内容添加:

location ~ /(data|uploads|templets)/.*\.(php|php5)?$ {

deny all;

}

apache 虚拟主机

NameVirtualHost *:80

<VirtualHost *:80>
ServerName localhost
DocumentRoot D:\root
</VirtualHost>

<VirtualHost *:80>
ServerName ndj.iciba.com
DocumentRoot D:\root\dj\dj.iciba.com\webapp\dj.iciba.com\wwwroot
RewriteEngine On
RewriteRule ^/([a-z]+).shtml$ /list.php?tag=$1
RewriteRule ^/([a-z]+)_(\d+).shtml$ /list.php?tag=$1&page=$2
RewriteRule ^/flash/([a-z]+)/(\d+).shtml$ /flash.php?flashid=$2
</VirtualHost>