让你的服务器更安全的20个配置[转] 

当然,这只针对于apache httpd server。不过其中的一些方面,同样适用于nginx、lighttpd、cherokee、hiawatha等非主流服务器系统.

1.首先确保已经打好了全部已知安全补丁....

2.隐藏掉服务器的版本等敏感信息.
ServerSignature Off
ServerTokens Prod

3.确保httpd是以它自己的用户和组在运行.
User apache
Group apache

4.确保只有网站根目录下的文件才可以通过web被访问.
<Directory />
Order Deny,Allow
Deny from all
Options None #这个可以被局部参数覆盖
AllowOverride None #这个可以被局部参数覆盖
</Directory>

5.关闭目录结构列表
Options -Indexes

6.关闭服务器端的配置文件包括
Options -Includes

7.关闭CGI执行本地脚本(真的很危险)
Options -ExecCGI

8.关闭软链
Options -FollowSymLinks

9.如果可以的话,建议关闭Options 的所有功能.
Options None

或者综上四点所述
Options -ExecCGI -FollowSymLinks -Indexes

10.关闭.htaccess 支持
AllowOverride None

如果必须启用的话可以考虑改名,并限制访问
AccessFileName .httpdoverride
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</Files>

11.确保httpd已载入mod_security模块,并运行.
LoadModule mod_security mod_security.so
下载地址:http://www.modsecurity.org/

12.去除掉不需要的模块.
可以使用 grep LoadModule httpd.conf 查看所有模块.

下面是一些通常不需要的而普遍被启用的模块:
mod_imap, mod_include, mod_info, mod_userdir, mod_status, mod_cgi, mod_autoindex.

13.确保只有root拥有对httpd配置文件和程序文件的读写权限.
chown -R root:root /path/to/apache
chmod -R o-rwx /path/to/apache

14.减少请求超时时间间隔
Timeout 45 #默认是300s

15.限制请求体大小,以防超大文件
LimitRequestBody 1048576

同样作用的配置还有:
LimitRequestFields, LimitRequestFieldSize 和 LimitRequestLine

16.限制XML请求体的大小
LimitXMLRequestBody 10485760
当然,这只适用于apache httpd 集成了SVN的服务器.

17.限制并发请求
MaxClients ??? #根据各自服务器内存适量设置

相关的配置项:
MaxSpareServers, MaxRequestsPerChild
ThreadsPerChild, ServerLimit,MaxSpareThreads 适用于apache2.x

18.限制IP访问
Order Deny,Allow
Deny from all
Allow from 127.0.0.1

19.调节保持存活时间
MaxKeepAliveRequests ??? #根据各自服务器内存适量设置
KeepAliveTimeout ??? #根据各自服务器内存适量设置

20.确保httpd运行在chroot 环境
SecChrootDir /chroot/apache

这样,apache httpd 就运行在虚拟的系统里,就算被hack了,也不会影响到真实系统.

___END___

这篇文章是我最近一不小心看到的,虽然是发表于2005年,有点过时了.囧rz
不过觉得很有帮助.特别是网络管理员来讲.

原文地址:20 ways to Secure your Apache Configuration
[ ] ( 1880 次浏览 ) 永久链接 ( 3 / 2757 )
编译安装 PHP 5.2.13 

下载5.2.x 分支最新版本5.2.13,解压

我的configure:

$ ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/sbin/apxs --enable-mod-charset --enable-fastcgi --with-config-file-path=/etc --enable-safe-mode --with-openssl --with-kerberos --with-zlib --with-bz2 --enable-calendar --with-curl --enable-exif --enable-ftp --with-gd --with-ttf --enable-mbstring --with-mcrypt --with-mhash --with-mysql=/usr/local/mysql --enable-embedded-mysqli --enable-sockets --enable-zip

检查依赖没有问题.
缺依赖的话就一个个安装xxx-devel.

进行 make,在编译到zend解释器时就报错了,错误很强大...

virtual memory exhausted: Cannot allocate memory
make: *** [Zend/zend_execute.lo] Error 1

虚拟内存不足,囧rz.. 没有办法,把mysqld,sendmail,httpd等其他进程先全部kill掉,腾出点内存来

再次make,还好,通过了.

不过,好景不长。就在编译行将结束时,再次中断报错...

/usr/bin/ld: cannot find -lltdl
collect2: ld returned 1 exit status
make: *** [libphp5.la] Error 1

是缺少libtool依赖,解决方案:
yum install libtool-ltdl-devel.

make clean && make .这次终于通过了,呵呵

复制源码包下php.ini-dist 到 /etc 下。稍加编辑即可.
libphp5.so 已自动生成到apache 的modules 目录下.
只需启动apache就可以了.

不过,生成的这个模块,好像不支持apache 2.3.5 alpha,不能被load进来.

报错如下:
httpd: Syntax error on line 64 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: undefined symbol: unixd_config

不知道是bug还是什么?

同样的源码,在apache 2.2.15 下生成的libphp5.so,加载成功.

待解...
[ ] ( 4237 次浏览 ) 永久链接 ( 3 / 2541 )
成功编译 apache httpd server 2.3.5 alpha 最终通过 

通过在maillist的学习,看了很多人的编译过程,特别是一篇编译 2.3.4 alpha 的例子,很受启发.
发现原来是expat的问题.

我的configure:

$ ./configure --prefix=/usr/local/apache2 --bindir=/usr/local/bin --sbindir=/usr/local/sbin --enable-v4-mapped --enable-maintainer-mode --enable-file-cache --enable-cache --enable-disk-cache --enable-so --enable-echo --enable-charset-lite --enable-mime-magic --enable-expires --enable-headers --enable-usertrack --enable-session --enable-session-cookie -enable-ssl --enable-http --enable-dav --enable-info --enable-dav-fs --enable-vhost-alias --enable-imagemap --enable-rewrite --with-included-apr

运行报错,configure failed in srclib/expat.
解决方案:yum install expat-devel,即可

再次运行,报错,不过这次是缺依赖.

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

原来apache httpd 从2.3.x 后不再集成pcre.须自行安装.
下载:
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.01.tar.bz2

解压,configure --prefix=/usr/local/pcre --enable-utf8 --enable-pcregrep-libz
make && make install.

然后回到apache httpd 源码包,加上一条 --with-pcre=/usr/local/pcre。即可顺利通过编译.
[ ] ( 1870 次浏览 ) 永久链接 ( 3.1 / 2505 )
编译安装mysql 5.5.2 M2 通过 

下载最新的mysql 发行版5.5.2 ,目前还是测试阶段。

我的具体步骤:

shell> groupadd mysql
shell> useradd -g mysql mysql

shell> $ ./configure --prefix=/usr/local/mysql --bindir=/usr/local/bin --sbindir=/usr/local/sbin --disable-dependency-tracking --enable-profiling --with-charset=utf8 --with-extra-charsets=all --with-server-suffix --with-unix-socket-path=/var/tmp/mysql.sock --with-mysqld-user=mysql --with-zlib-dir=bundled --with-big-tables --with-embedded-server --with-embedded-privilege-control

shell> make
这里报了错,提示缺少g++ ,囧rz
于是 yum install gcc-c++, make clean,再次make 通过.

shell> make install
再次报错,提示变量已声明。
原来是缺少g++ 检查依赖的后果.
于是重复上面两步.通过

shell> cp support-files/my-medium.cnf /etc/my.cnf (内容酌情编辑)
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> mysql_install_db
shell> chown -R root .
shell> chown -R mysql var
shell> mysqld_safe --user=mysql &
服务启动成功.
[ ] ( 1889 次浏览 ) 永久链接 ( 3 / 2431 )
在Centos下编译安装 apache httpd server 2.2.15 

受朋友所托,帮忙在一台新的VPS上搭建个LAMP.

本来想安装最新的apache 2.3.5 alpha 的,不过在交叉编译 APR 和 APR-util 上没通过.

搞了很久也么没弄明白是怎么回事,谷歌搜索了下,有人说是libtool版本太低,也有说在x64 机器上会导致这个问题,感觉不可能。因为是源码编译的.

已经向apache httpd 的maillist 提出了问题,等人回答了。。

也不能闲着,于是下载了2.2.x 分支的最新2.2.15 先安装下,

我的configure:


It was created by configure, which was
generated by GNU Autoconf 2.63. Invocation command line was

$ ./configure --prefix=/usr/local/apache --enable-v4-mapped --enable-maintainer-mode --enable-file-cache --enable-cache --enable-disk-cache --enable-so --enable-echo --enable-charset-lite --enable-mime-magic --enable-expires --enable-headers --enable-usertrack --enable-session --enable-session-cookie --enable-session-crypto -enable-ssl --enable-http --enable-dav --enable-info --enable-dav-fs --enable-vhost-alias --enable-imagemap --enable-rewrite --with-included-apr

这次很顺利。也佐证了libtool应该是没问题的.

之后就是make & make install.

至于 2.3.5 alpha,只有等高人解答了
[ ] ( 3267 次浏览 ) 永久链接 ( 3 / 2330 )

<< <上一页 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 下一页> >>