注:这个是一个简单的上手配置
安装的nginx需要支持url重写,gzip压缩,ssl请求,静态文件缓存,因此需要先安装相关的库,将附件中的文件放置到/usr/local/src目录下
此库支持url重写
tar -zxvf pcre-8.21.tar.gz
cd pcre-8.21
./configure
make
make install
此库支持gzip压缩
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make
make install
tar -zxvf openssl-1.0.1c.tar.gz
tar zxvf ngx_cache_purge-1.0.tar.gz
tar -zxvf nginx-0.8.55.tar.gz
cd nginx-0.8.55
./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--add-module=/usr/local/src/ngx_cache_purge-1.0 \
--with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.21 \
--with-zlib=/usr/local/src/zlib-1.2.8 \
--with-openssl=/usr/local/src/openssl-1.0.1c
make
make install
二、配置nginx:修改nginx.conf 主要修改的地方为将对应的项目转发到对应的tomcat 配置不同项目的tomcat(增加upstream)
如:
upstream tomcat_EP_portal {
server 127.0.0.1:8088 weight=1 max_fails=2 fail_timeout=30s;
} upstream tomcat_EP_admin {
server 127.0.0.1:8092 weight=1 max_fails=2 fail_timeout=30s;
}
然后增加对应的server:配置不同的项目域名;
如:
location /admin/ {
proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://tomcat_EP_admin;
}
location /portal/ {
proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://tomcat_EP_portal;
}
其他:
静态化:也可用rewrite 重写url
rewrite /([_a-zA-Z0-9]+)\/?$ /$1/home.html last; rewrite /([_a-zA-Z0-9]+)/page-([0-9a-zA-Z]+)\.html$ /render.cz?method=showPage&store=$1&pageId=$2 last;
静态文件:
#静态文件,nginx自己处理
location ~ /(images|javascript|js|css|flash|media|static)/ {
root c:/dev/netcloudHarden/server/public_html; expires 1d;
}
三、启动运行:
检查配置文件是否正确:/usr/local/nginx/nginx -t;
启动: /usr/local/nginx/nginx
ps -ef |grep nginx
停止:kill -QUIT cat /usr/local/nginx/nginx.pid