编译,安装
(多次编译或重新编译, 请执行make clean, make mrproper)
./configure --prefix=/usr/local/apache --enable-mods-shared=all --enable-so --with-mpm=worker --with-included-apr --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr
./configure --prefix=/usr/local/apache2.2 --enable-mods-shared=all \
--enable-so --with-mpm=worker --enable-deflate \
--enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache \
--enable-proxy --enable-suexec --with-included-apr --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr
make
make install
make mrproper
或者连续执行 make && make install && make mrproper
配置
cd /usr/local/apache/conf (下面的LINUX命令都是以conf为当前目录)
(1.)httpd.conf
修改如下几项
DocumentRoot /home/test
并在末尾增加如下字段:
#LoadModule jk_module modules/mod_jk.so
Include /usr/local/apache/conf/Includes/*.conf
#转发规则 START
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don't compress images
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$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \
\.(css|js)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \
\.(mp3|amr|mid|MP3)$ no-gzip dont-vary
# 确保代理不会发送错误的内容
Header append Vary User-Agent env=!dont-vary
#转发规则 END
(2)配置 MOD_JK
复制mod_jk.so到modules/下
1.配置mod_jk.conf
vi Includes/mod_jk.conf
增加如下内容:
LoadModule jk_module modules/mod_jk.so
#mod_jk workers.properties
JkWorkersFile /usr/local/apache2/conf/workers.properties
# Where to put jk logs
JkLogFile /usr/local/apache2/logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
# ...servlet .jsp....ajp13.....Tomcat..Tomcat...
JkMount /*.jsp loadbalancer
JkMount /*.do loadbalancer
JkMount /servlet/* loadbalancer
JkMount /jsp-examples/* loadbalancer
2.配置workers.properties(一般只需改动对应HOST)
vi workers.properties
ps=/
# list the workers by name
worker.list=tomcat1, loadbalancer
# ------------------------
# First tomcat server
# ------------------------
worker.tomcat1.port=8009
worker.tomcat1.host=123.108.208.17
worker.tomcat1.type=ajp13
# Specify the size of the open connection cache.
#worker.tomcat1.cachesize
#
# Specifies the load balance factor when used with
# a load balancing worker.
# Note:
# ----> lbfactor must be > 0
# ----> Low lbfactor means less work done by the worker.
worker.tomcat1.lbfactor=100
# ------------------------
# Load Balancer worker
# ------------------------
# The loadbalancer (type lb) worker performs weighted round-robin
# load balancing with sticky sessions.
# Note:
# ----> If a worker dies, the load balancer will check its state
# once in a while. Until then all work is redirected to peer
# worker.
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=tomcat1
#
# END workers.properties
#
3.配置对应虚拟主机
vi Includes/examples.com.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /home/test
ServerName www.test.com
ServerAlias www.test.com
ErrorLog logs/www.test.com-error_log
CustomLog logs/www.test.com-access_log common
<Directory "/home/test">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
4.配置静态页面压缩输出模块deflate
这个扩展模块在安装apache的时候已经动态的编译到apache里去了。现在进行配置。
# cd /usr/local/apache2.2/conf/Includes
上面添加的是apache扩展配置文件的目录
# vi mod_deflate.conf
在配置文件里添加如下语句
5. 配置mod_cache模块
# cd /usr/local/apache2.2/conf/Includes
# vi mod_cache.conf
在配置文件里添加如下语句
#LoadModule disk_cache_module modules/mod_disk_cache.so
CacheRoot /
CacheSize 256
CacheEnable disk /
CacheDirLevels 5
CacheDirLength 3
LoadModule mem_cache_module modules/mod_mem_cache.so
CacheEnable mem /
MCacheSize 4096
MCacheMaxObjectCount 100
MCacheMinObjectSize 1
MCacheMaxObjectSize 2048
测试&启动
./bin/apachectl -t 测试配置有无语法错误
./bin/apachectl start 启动APACHE服务
./bin/apachectl stop 停止APACHE服务