查看文章
 
FreeBSD安装之AMP的安全设置
2007年07月25日 星期三 下午 3:36

杨伟<e4twood@gmail.com>

欢迎转载,请保证文章的完整性

在上一节中,我们安装了ApacheMySQLPHP(简称:AMP)。在这一节,我们来做一下简单的AMP下的一些常用的安装设置。

 

PHP安全设置

编辑php.ini文件

#ee /usr/local/etc/php.ini

#查找disable_functions=修改为disable_functions=exec,system,passthru,error_log,ini_alter,dl,openlog,syslog,readlink,symlink,link,leak,fsockopen,proc_open,popepassthru,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,popen
查找display_errors修改为:

display_errors=Off
查找magic_quotes_gpc修改为:

magic_quotes_gpc=Off
查找register_globals修改为:
register_globals=Off
查找open_basedir修改为:
open_basedir=/www/:/tmp/
注:这里是限制php可以访问的目录,后面一定要加上/,否则如果有/wwwabcd这个目录也会被访问得到多个目录用英文:分隔。/www/:/tmp/这点根据自己的需要进行修改

MySQL安全设置

#cp /usr/local/share/mysql/my-medium.cnf   /etc/my.cnf
#ee /etc/my.cnf

#myisam_sort_buffer_size = 8M后添加
set-variable=local-infile=0
set-variable=max_connections=9000
#
port=3306更改为:
port=3300 #
这里的3300为你自己定义的端口号
#
[mysqld]下加入:
bind-address = 127.0.0.1


更改MySQLroot用户名

#mysql –uroot –p

mysql>use mysql;
mysql> update user set user="admin" where user="root";
mysql> flush privileges;
mysql>quit;

这样MySQL默认的管理员用户名就由root更改为admin

 

Apache安全设置
修改httpd.conf文件修改以下内容

#加入以下内容
<IfModule prefork.c>
StartServers 10
MinSpareServers 10
MaxSpareServers 15
ServerLimit 2000
MaxClients 1500
MaxRequestsPerChild 0              
</IfModule>
AddDefaultCharset GB2312
ServerTokens Prod           
ServerSignature Email   
#
关闭默认的目录索引。将Options Indexes FollowSymLinks修改为:
Options FollowSymLinks      

使用MOD_LIMITIP限制IP连接数

#wget http://www2.laohekou.com.cn/e4twood/security/limt.tar.gz
#tar zxvf limt.tar.gz
#cd mod_limitipconn-0.22
#ee Makefile //修改成你的系统的相关路径
#make install clean

修改httpd.conf文件让apache支持MOD_LIMTIP

<IfModule mod_limitipconn.c>
<Location / >                         #
设置要控制的目录
MaxConnPerIP 3                       #
限制单IP最大进程数
NoIPLimit image/*                    #
非限制的文件类型
</Location>
<Location /mp3>
MaxConnPerIP 1
OnlyIPLimit audio/mpeg video         #
可选限制的文件类型
</Location>
</IfModule>


apache更为安全的方式,加载ModSecurity模块的方式。
首先下载,并安装ModSecurity,让apache能够的支持它。

#cd /tmp

#wget http://www.modsecurity.org/download/modsecurity-apache_1.9.4.tar.gz
#tar zxvf modsecurity-apache_1.9.4
#cd modsecurity-apache_1.9.4/apache2
/usr/local/sbin/apxs –cia mod_security.C

安装完成后,系统会提示:

activating module `security' in /apache_directory/httpd.conf]

这时我们就需要在httpd.conf下加下语句:

#cd /usr/local/etc/apache22/
#ee httpd.conf

<IfModule mod_security.c>

Include etc/apache22/security/*.conf

</Ifmodule>

保存退出后,在apache22目录下新建一个security的目录,并将一些默认的配置文件下载至该目录。

#mkdir security
#cd security
#wget  http://www2.laohekou.com.cn/e4twood/security/expe.conf
#wget   http://www2.laohekou.com.cn/e4twood/security/gerl.conf
#wget   http://www2.laohekou.com.cn/e4twood/security/hard.conf
#wget   http://www2.laohekou.com.cn/e4twood/security/out.conf
#wget   http://www2.laohekou.com.cn/e4twood/security/php.conf

再次重启apache启可

#/usr/local/etc/rc.d/apache22.sh restart

 


类别:Freebsd||添加到搜藏 |分享到i贴吧|浏览(231)|评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
     

   
帮助中心 | 空间客服 | 投诉中心 | 空间协议
©2012 Baidu