Apache2.4 性能優化

前幾天買了阿里雲主機後,配置了基本的web環境,apache性能沒有作優化;致使今天在公佈opms系統的時候,訪問太慢,自己的雲主機配置是低配,本身玩的。具體環境配置請看《再談centOS7.2 LAMP源碼安裝及注意要點》。javascript

現把apache性能優化上作一下配置:css

一. deflate和expireshtml

我在安裝apache的時候,已經自動靜態編譯了deflate和expires模塊,因此可能在配置文件裏直接添加相關指令:java

#deflate gzip啓用 能夠在主機配置文件httpd.conf或虛擬主機vhost下添加下面指令
DeflateCompressionLevel 9
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE image/gif image/png image/jpe image/swf image/jpeg image/bmp

#expires 緩存模塊,這裏配置了1天的時間,後面的單位能夠months,years,weeks,hours,seconds,minutes
#能夠在主機配置文件httpd.conf或虛擬主機vhost下添加下面指令
ExpiresActive on
ExpiresDefault "access plus 1 days」
ExpiresByType text/html "access plus 1 days"
ExpiresByType text/css "access plus 1 days」
ExpiresByType image/gif "access plus 1 days」
ExpiresByType image/jpeg "access plus 1 days」
ExpiresByType image/jpg "access plus 1 days」
ExpiresByType image/png "access plus 1 days」
EXpiresByType application/x-shockwave-flash "access plus 1 days"
EXpiresByType application/x-javascript "access plus 1 days"
ExpiresByType video/x-flv "access plus 1 days"

  二. 隱藏服務器版本信息web

打開httpd-default.conf,  同時刻記得把httpd.conf中「#」去掉apache

ServerTokens Prod
ServerSignature Off

 三. 啓用worker模式,提高併發數(能夠達到2000-5000)vim

StartServers 3
MaxClients 2000
ServerLimit 25
MinSpareThreads 50
MaxSpareThreads 200
ThreadLimit 200
ThreadsPerChild 100
MaxRequestsPerChild 0

四.  刪除掉cgicentos

在httpd.conf刪除自帶的cgi指令緩存

五. 其它性能優化

如防盜鏈等

六. centos

vim /etc/sysctl.conf 

net.ipv4.ip_local_port_range = 1024 65535
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_fin_timeout = 10
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_timestamps = 0  
net.ipv4.tcp_window_scaling = 0
net.ipv4.tcp_sack = 0
net.core.netdev_max_backlog = 30000
net.ipv4.tcp_no_metrics_save=1
net.core.somaxconn = 4096
net.ipv4.tcp_syncookies = 0
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2

生效:

/sbin/sysctl -p /etc/sysctl.conf
/sbin/sysctl -w net.ipv4.route.flush=1
相關文章
相關標籤/搜索