基于ubuntu 的LAMP 优化加固

很多朋友都喜欢用ubuntu,很大原因是它安装LAMP非常简单,

尽管默认安装的lamp已经可以良好工作,但是系统管理员仍然可以找到一些优化加固的空间。


1、php加速

事实证明,php解释缓存可以提高php效率,apc/xcache/zendopcache等各个加速器原理都差不多,性能也相差不大,可以肯定是,php解释缓存,使用与不使用,性能相差数倍甚至更多。

apt-get install php-apc


2、php5-mysql 模块精简

php5-mysql 软件包默认包含了3种mysql连接方式,分别是mysql,pdo_mysql和mysqli,

三者虽各有优劣,但你用到的肯定只有其中的一种,通常是mysql。

cd /etc/php5/conf.d/
mv mysqli.ini mysqli.ini.bak
mv pdo_mysql.ini pdo_mysql.ini.bak
mv pdo.ini pdo.ini.bak


3、隐藏apache和php的版本信息

sed -i 's/ServerTokens OS/ServerTokens Prod/g' /etc/apache2/conf.d/security
sed -i 's/ServerSignature On/ServerSignature Off/g' /etc/apache2/conf.d/security
sed -i '/expose_php/{s/On/Off/g}' /etc/php5/apache2/php.ini

4、安装mod_security

mod_security 是一个安全模块,可以防止多种***。

apt-get install libapache-mod-security
cd /etc/modsecurity/
cp modsecurity.conf-recommended modsecurity.conf


5、设置压缩和浏览器缓存

压缩数据可提升吞吐量,设置浏览器缓存可减少请求数,反向提高apache性能。

cat /etc/apache2/httpd.conf
<IfModule mod_deflate.c>
         <Location />
                # Insert filter
                SetOutputFilter DEFLATE
                # Netscape 4.x has same problems...
                BrowserMatch ^Mozilla/4 gzip-only-text/html
                # Netscape 4.06-4.08 have some more problems
                BrowserMatch ^Mozilla/4\.0[678] no-gzip
                # MSIE masquerades as Netscape, but it is fine
                # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
                # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
                # the above regex won't work. You can use the following
                # workaround to get the desired effect:
                BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
                # Don't compress images and other
                SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
                SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
                SetEnvIfNoCase Request_URI .(?:pdf|doc)$ no-gzip dont-vary
                AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
                AddOutputFilterByType DEFLATE application/x-javascript
                # Make sure proxies don't deliver the wrong content
                #Header append Vary User-Agent env=!dont-vary
         </Location>
 </IfModule>
<IfModule mod_expires.c>
        ExpiresActive On
        ExpiresByType image/* "access plus 1 month"
        ExpiresByType text/css "access plus 1 month"
        ExpiresByType text/javascript  "access plus 1 month"
        ExpiresByType application/x-javascript "access plus 1 month"
</IfModule>
<IfModule mod_headers.c>
  Header unset Server
  Header unset X-Powered-By
</IfModule>


以上几点在实际中是不够的,另外给出3点额外的建议:


a、mysql独立出来

除非逼不得已,请务必单独给mysql数据库分配一台机器。要知道,lamp不是一个整体,而是一种耦合。


b、使用apache基于域名的虚拟主机

基于域名的主机由于通常无法直接通过IP地址访问,这可以减少很多扫描和盲注,让网站更安全。


c、反向代理

如果在lamp前面单独放置一台机器做nginx反向代理,把web服务器放入内网,这样在架构上会更安全,还可以通过nginx的负载均衡来增加web服务器的可用性。lamp如果直接面对公网,面临的危险显然更多。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值