UbuntuでLAMP環境の合理化、高速化、最適化などを設定する対策

1.php加速
apt-get install php-apc

2.php5-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/securitysed -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>

 

Source

Posted by arkgame