下載httpd源碼包
wget http://archive.apache.org/dist/httpd/httpd-2.2.25.tar.gz
tar -xvf httpd-2.2.25.tar.gz
cd httpd-2.2.25.tar.gz
版本信息的屏蔽
1.編譯前翅雏,屏蔽版本信息
vim include/ap_release.h
#define AP_SERVER_BASEVENDOR "Apache Software Foundation" #服務的供應商名稱
#define AP_SERVER_BASEPROJECT "Apache HTTP Server" #服務的項目名稱
#define AP_SERVER_BASEPRODUCT "Apache" #服務的產品名
#define AP_SERVER_MAJORVERSION_NUMBER 2 #主要版本號
#define AP_SERVER_MINORVERSION_NUMBER 4 #小版本號
#define AP_SERVER_PATCHLEVEL_NUMBER 6 #補丁級別
#define AP_SERVER_DEVBUILD_BOOLEAN 0 #
2.對apache進行編譯安裝
yum install openssl*
./configure --prefix=/usr/local/apache2.2.25/ --enable-so --enable-rewrite --enable-ssl --with-mpm=worker
配置參數用途
--perfix=/usr/local/apache2.2.25 指定安裝路徑
--enable-so 支持動態(tài)加載模塊
--enable-rewrite 支持網站地址重寫
--enable-ssl 支持ssl加密
--with-mpm=worker 更改Apache運行模式為
make -j 4 && make install 安裝
3.再次隱藏服務信息
vim /usr/local/apache2.2.25/conf/httpd.conf
Include conf/extra/httpd-default.conf 取消注釋
vim /usr/local/apache2.2.25/conf/extra/httpd-default.conf
ServerTokens Full ===》》ServerTokens Prod 不顯示服務器操作系統類型
ServerSignature On ===》》ServerSignature OFF 不顯示web服務版本號和模塊版本
4.啟動apache
cp /usr/local/apache2.2.25/bin/apachectl /etc/init.d/apachectl
/etc/init.d/apachectl -k start
重載
/etc/init.d/apachectl -k gracefu
長連接功能
優(yōu)點:保持連接硫狞,減少三次握手浸船,但是會小號內存
1.開啟長連接
vim /usr/local/apache2.2.25/conf/httpd.conf
在Lient
KeepAlive on
KeepAliveTimeout 15 #保持長連接的時長
#MaxKeepAliveRequests #保持長連接后允許發(fā)送的請求數柿扣,一般不需要配置画侣,默認100
壓縮功能
1.查看模塊時候安裝
/usr/local/apache2.2.25/bin/apachectl -M | grep defalte
Syntax OK 沒有安裝
defalte_module(static) 編譯時已安裝
defalte_module(shared) 以DSO的方式安裝
DSO安裝方法:
cd /root/httpd-2.2.25/modules/filters
/usr/local/apache2.2.25/bin/apxs -c -i -a /root/httpd-2.2.25/modules/filters/mod_deflate.c
安裝完成后http.conf文件 54行左右會有
LoadModule deflate_module modules/mod_deflate.so
以下配置文件在這行下添加
2.配置壓縮模塊
vim /usr/local/apache2.2.25/conf/httpd.conf
<ifModule mod_deflate.c>
DeflateCompressionLevel 9 壓縮等級数冬,越大效率越高,消耗CPU也越高
SetOutputFilter DEFLATE
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript
#限制特定的MIME類型文件
</ifmodule>
對apache進行重啟
/usr/local/apache2.2.25/bin/httpd -k graceful 重新加載配置文件
緩存功能
1.DSO安裝
/usr/local/apache2.2.25/bin/apxs -i -c -a /root/httpd-2.2.25/modules/metadata/mod_expires.c
2.修改配置文件httpd.conf
使用
對全局 對目錄 對虛擬機
vim /usr/local/apache2.2.25/conf/httpd.conf
<IfModule !mpm_winnt_module>
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 12 month"
ExpiresByType text/html "access plus 12 months"
ExpiresByType text/css "access plus 12 months"
ExpiresByType image/gif "access plus 12 months"
ExpiresByType image/jpeg "access plus 12 months"
ExpiresByType image/jpg "access plus 12 months"
ExpiresByType image/png "access plus 12 months"
EXpiresByType application/x-shockwave-flash "access plus 12 months"
EXpiresByType application/x-javascript "access plus 12 months"
ExpiresByType video/x-flv "access plus 12 months"
</IfModule>
對apache進行重啟
/etc/init.d/apachectl graceful 重新加載配置文件
Apache運行模式worker
1.查看apache是否運行work模式
/usr/local/apache2.2.25/bin/httpd -l | grep work
2.修改配置文件
vim /usr/local/apache2.2.25/conf/httpd.conf
最后一行添加
<IfModule worker.c>
StartServers 2 最初建立的子進程
MaxClients 150 apache同時支持的并發(fā)量
MinSpareThreads 25 最小空閑線程操灿,如果線程小于這個值锯仪,自動創(chuàng)建線程
MaxSpareThreads 75 最大線程數,如果縣城大于這個值趾盐,自動kill掉多余線程
ThreadsPerChild 25 每個子迚程包含固定的線程數
MaxRequestsPerChild 0 每個子迚程可以支持的請求數庶喜,這要設置為 0
</IfModule>