阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

基于Ubuntu 的LAMP 优化加固

95次阅读
没有评论

共计 2680 个字符,预计需要花费 7 分钟才能阅读完成。

很多朋友都喜欢用 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>

 

Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置 http://www.linuxidc.com/Linux/2013-06/86250.htm

CentOS 5.9 下编译安装 LAMP(Apache 2.2.44+MySQL 5.6.10+PHP 5.4.12) http://www.linuxidc.com/Linux/2013-03/80333p3.htm

RedHat 5.4 下 Web 服务器架构之源码构建 LAMP 环境及应用 PHPWind http://www.linuxidc.com/Linux/2012-10/72484p2.htm

LAMP 源码环境搭建 WEB 服务器 Linux+Apache+MySQL+PHP http://www.linuxidc.com/Linux/2013-05/84882.htm

更多 Ubuntu 相关信息见 Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计2680字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中