nginx整合tomcat
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/sofewareshell>tar zxf pcre-8.10.tar.gz &&cd pcre-8.10shell>./configure && make && make installshell>cd ..shell>tar zxf agentzh-headers-more-nginx-module-v0.15rc2-0-g2c629de.tar.gzshell>tar zxf nginx-upstream-jvm-route-0.1.tar.gzshell>tar zxf nginx-1.0.4.tar.gzshell>cd nginx-1.0.4shell>patch -p0 < /home/sofeware/nginx_upstream_jvm_route/jvm_route.patchshell>./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
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载