1、准备软件(存放在目录/home/sofeware下)

agentzh-headers-more-nginx-module-v0.15rc2-0-g2c629de.tar.gz  #支持隐藏头部信息  (不是必须,觉得需要就安装吧)

nginx-upstream-jvm-route-0.1.tar.gz   #nginx会话记录的必须模块   (用于tomcat集群,单tomcat就直接忽略相关操作)

pcre-8.10.tar.gz    #包括 perl 兼容的正规表达式库 (shell>rpm -qa|grep pcre 可以检查系统是否已存在)

nginx-1.0.4.tar.gz

apache-tomcat-7.0.11.tar.gz  (安装相对简单、资料也比较多,这里不演示了)

2、 编译安装

shell>cd /home/sofeware
shell
>tar zxf pcre-8.10.tar.gz &&cd pcre-8.10
shell
>./configure && make && make install
shell>cd ..
shell
>tar zxf agentzh-headers-more-nginx-module-v0.15rc2-0-g2c629de.tar.gz
shell
>tar zxf nginx-upstream-jvm-route-0.1.tar.gz
shell
>tar zxf nginx-1.0.4.tar.gz
shell
>cd nginx-1.0.4
shell
>patch -p0 < /home/sofeware/nginx_upstream_jvm_route/jvm_route.patch
shell
>./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
--add-module=/home/sofeware/nginx_upstream_jvm_route/
--add-module=/home/sofeware/agentzh-headers-more-nginx-module-2c629de/
&& make && make install

3、配置 (默认80端口)

配置文件:/usr/local/nginx/conf/nginx.conf

//运行nginx所在的用户名和用户组
user nginx nginx;
worker_processes
1;
//全局错误日志及PID文件
error_log /usr/local/nginx/logs/error.log;
pid
/usr/local/nginx/nginx.pid;
events {
worker_connections
1024;
}
http {
include mime.types;
default_type application
/octet-stream;
//全局访问日志
access_log /usr/local/nginx/logs/access.log;
sendfile on;
keepalive_timeout
65;
server {
listen
80;
server_name localhost;
root /var/www/test; //网站根目录
#charset koi8
-r;
access_log
/usr/local/nginx/logs/host.access.log;
location
/ {
//将index.jsp 加入到默认的访问首页地址
index index.html index.htm index.jsp;
}
//所有jsp的页面均交由tomcat处理
location ~ .*.jsp$ {
index index.jsp;
proxy_pass http:
//localhost:8080;
}
//设定访问静态文件直接读取不经过tomcat
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
location
~ .*\.(js|css)?$ {
expires 1h;
}
error_page
500 502 503 504 /50x.html;
location
= /50x.html {
root html;
}
}

4、测试配置

shell>/usr/local/nginx/sbin/nginx -t
//出现如下信息表示配置成功,否则检查配置文件
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok  
the configuration file
/usr/local/nginx/conf/nginx.conf was tested successfully

5、启动、、重启、停止

shell>/usr/local/nginx/sbin/nginx //启动
shell>/user/local/nginx/sbin/nginx -s reload //重启
shell>/usr/local/nginx/sbin/nginx -s stop //停止

6、添加新模块(非覆盖安装)

NginxHttpRealIpModule //有些网站使用这样的方式来搭建分布式缓存,若干台Squid放在前面提供缓存服务,内容从后面的 Nginx获取。不过如此一来,Nginx日志里看到的IP就是Squid的IP了,为了能让Nginx透明获取IP,可以使用 NginxHttpRealIpModule

ngx_cache_purge-1.3.tar.gz  //通过该模块使得Nginx可以像squid使用PURGE指令手动清除指定URL的缓存页面

shell>/usr/local/nginx/sbin/nginx -s stop //关闭nginx服务
shell>tar zxf ngx_cache_purge-1.3.tar.gz
shell
>cd ..
shell
>tar zxf nginx-1.0.4.tar.gz
shell
>cd nginx-1.0.4
shell
>patch -p0 < /home/sofeware/nginx_upstream_jvm_route/jvm_route.patch
shell
>./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
--with-http_realip_module //新增模块
--add-module=/home/sofeware/nginx_upstream_jvm_route/
--add-module=/home/sofeware/agentzh-headers-more-nginx-module-2c629de/
--add-module=/home/sofeware/ngx_cache_purge-1.3/ //新增模块
shell>make //编译即可,无需make install
shell>mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak //备份执行文件
shell>cp -r objs/nginx /usr/local/nginx/sbin/
shell
>/usr/local/nginx/sbin/nginx -t //测试是否通过
shell>rm -rf /usr/local/nginx/nginx.pid //删除PID,具体文件路径按自己的配置的实际情况
shell>/usr/local/nginx/sbin/nginx //重启
shell>/usr/local/nginx/sbin/nginx -V //查看编译参数
posted on 2011-06-19 13:47  Nicholas_F  阅读(3391)  评论(0编辑  收藏  举报