一,Nginx安装
1,建立用户和用户组
#groupadd www
#useradd -g www -s /sbin/nologin www
2,下载pcre,openssl,nginx和nginx_upstream_jvm_route的源码
3,编译安装Nginx
cd /opt/nginx
patch -p0 < /opt/nginx_upstream_jvm_route/jvm_route.patch
./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --user=www --group=www --with-pcre=/opt/pcre --with-openssl=/opt/openssl --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --add-module=/opt/nginx_upstream_jvm_route
make
make install
执行make的时候会遇到如下问题,就是一个cookie变量定义了但没使用的编译告警,该告警可能中断编译过程
gcc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I /opt/pcre -I /opt/openssl/.openssl/include -I objs -I src/http -I src/http/modules -I src/mail \
-o objs/addon/nginx_upstream_jvm_route/ngx_http_upstream_jvm_route_module.o \
/opt/nginx_upstream_jvm_route/ngx_http_upstream_jvm_route_module.c
/opt/nginx_upstream_jvm_route/ngx_http_upstream_jvm_route_module.c: 在函数‘ngx_http_upstream_get_jvm_route_peer’中:
/opt/nginx_upstream_jvm_route/ngx_http_upstream_jvm_route_module.c:321:15: 错误:变量‘cookie’被设定但未被使用 [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors
make[1]: *** [objs/addon/nginx_upstream_jvm_route/ngx_http_upstream_jvm_route_module.o] 错误 1
故干脆屏蔽掉cookie变量的声明和定义得了
//ngx_str_t cookie;
//cookie = jrp->cookie;
编译安装完成后
nginx执行文件生成在/usr/sbin目录下,而配置,日志文件在/usr/local/nginx目录下
二,Tomcat安装
简单地解压出来即可用
三,Nginx + Tomcat集成
需要修改nginx.conf配置文件,增加以下红色部分
注意:该配置文件只是简单将Nginx+Tomcat集成起来,不涉及Nginx调忧
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream tomcat_server {
server localhost:8080;
}
server {
listen 80;
server_name localhost;
index index.html index.htm index.jsp default.jsp index.do default.do;
#charset koi8-r;
#access_log logs/host.access.log main;
if (-d $request_filename)
{
rewrite ^/(.*)([^/])$http://$host/$1$2/ permanent;
}
location ~ \.(jsp|jspx|do|wsdl)?$ {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://tomcat_server;
}
location / {
root html;
index index.html index.htm;
}
.......
}
}
四,测试
启动Tomcat
/usr/local/apache-tomcat/bin/startup.sh
修改配置后重启Nginx
nginx -s reload
访问测试页面:http://localhost/examples/jsp/jsp2/simpletag/hello.jsp