safe_mode_exec_dir = --设定安全模式下可以执行程序的目录
disable_functions = 要关闭的函数,用\",\"分隔建议关闭phpinfo,get_cfg_var
expose_php = On 建议expose_php = Off,这样在header里就不会有php的版本号
display_errors =On 建议 display_errors =Off,这样所有错误信息,都将关闭
register_globals = Off 自动全局变量,一般都要打开register_globals = On,但会引发很多
安全问题,特别是一些写编写的不是很好的php脚本,有可能危及到你的web server
file_uploads = On 是否允许上传文件,如果你不需要就off
allow_url_fopen = Off 是否远程打开功能,建议关闭
;extension=php_gd.dll
;extension=php_gettext.dll
;extension=php_hyperwave.dll
;extension=php_iconv.dll
;extension=php_ifx.dll 打开一些需要支持的库,比如使用要使用图形函数
需要copy php/extensions/php_gd.dll到你的系统目录,然后去掉;
重新启动apache,就可以使用了
3.my.ini
上面有了,pass
安全建议,以上3个设置文件,把他们的权限设定为system所有权限,administrators所有权限
4.强化虚拟目录的安全性
一些重要的指令
具体的列子:
<Directory \"d:/Apache/htdocs/tools\">
Options Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
php_flag engine off ;关闭php解释执行功能
php_admin_value safe_mode 1 ;安全模式 1-打开 0-关闭
php_admin_value open_basedir d:/Apache/htdocs/tools ;限制在一个制定的目录
这样就限制了php脚本只能打开d:/Apache/htdocs/tools下的文件.
以下代码就没什么用了
-----------------------------------------------------------
$fd = fopen( $filename, \"r\" );
$view = fread($fd, filesize($filename));
echo \"<pre>\";
echo htmlspecialchars(\"$view\";);
echo \"</pre>\";
fclose( $fd );
-----------------------------------------------------------
启用apache-http验证功能
清除
<Directory \"d:/Apache/htdocs/home\">
...
...
allowoverride authconfig
</Directory>
中的
参数 allowoverride authconfig
注意的,这里的d:/Apache/htdocs/home,表示为我安装的apache服务的web根目录,你的和我的不一定一样
默认的,好象就没这个 allowoverride authconfig参数。
allowoverride authconfig参数的含义。
它的含义是,根目录下所有目录的访问控制由它目录下的.htaccess文件来设定。
这里,我要多说点废话了。
为什么是.htaccess,这个文件名,而不是其它的。
这个是在AccessFileName参数中定义的。默认的是这样。
AccessFileName .htaccess
你要做的清除allowoverride authconfig参数(加#或者删掉)
这样做的理由
1.我觉得麻烦(每个目录都需要放上.htaccess文件,且以\".\"开头的文件名在windows系统下,是不允许的。)
2.不太安全 (它有可能被人看到。)
如何对你所想要指定的目录进行验证?
一个列子
<Directory \"d:/Apache/htdocs/home\"> //定义要验证目录路径
AuthType Basic //方式,windows不支持md5,所以请使用basic方式
AuthName TEST //定义显示在对话框领域名字
AuthUserFile d:/Apache/user //定义密码文件
ErrorDocument 401 \"Error Password //定义验证失败后显示的内容,当然可以是文件了
require valid-user 注意,我这里让它直接显示Error Password,用\"开头就是了,只有一个哦
</Directory>
直接加到httpd.conf后面就是了。
然后在apache的安装目录里的bin目录里有个htpasswd.exe文件
请到cmd下运行它
d:\\Apache\\bin>htpasswd.exe
Usage:
htpasswd [-cmdps] passwordfile username
htpasswd -b[cmdps] passwordfile username password
htpasswd -n[mdps] username
htpasswd -nb[mdps] username password
-c Create a new file. //创建一个新的密码文件(你第一次使用,因该使用这个参数)
-n Don\'t update file; display results on stdout. //显示到屏幕
-m Force MD5 encryption of the password (default). //加密口令(md5方式)默认的
-d Force CRYPT encryption of the password. //使用CRYPT方式加密口令
-p Do not encrypt the password (plaintext). //不加密口令
-s Force SHA encryption of the password. //使用sha算法加密
-b Use the password from the command line rather than prompting for it. //互交方式
On Windows, TPF and NetWare systems the \'-m\' flag is used by default.
On all other systems, the \'-p\' flag will probably not work.
——————————————————————————————————————
列子: