编译安装pcre库
PCRE(Perl Compatible RegularExpressions)是一个Perl库,包括 perl 兼容的正规表达式。Pcre的作用主要是使nginx支持HTTPrewrite模块。
[root@Web-175 ~]# cd /opt/
[root@Web-175 opt]# tar -zxvf pcre-7.6.tar.gz
[root@Web-175 pcre-7.6]# ./configure
[root@Web-175 pcre-7.6]# make && make install
编译安装jpeg
Jpeg是一个基本的图像压缩方式。
[root@Web-175 opt]# tar -zxvf jpegsrc.v7.tar.gz
[root@Web-175 opt]# cd jpeg-7/
[root@Web-175 opt]# ./configure --enable-shared --enable-static
[root@Web-175 opt]# make && make install
创建nginx用户和组
useradd -s /sbin/nologin -M nginx
groupadd ngnix
[root@Web-175 opt]# tar -zxvfnginx-upstream-jvm-route-0.2.tar.gz
[root@Web-175 opt]# tar -zxvf nginx-0.8.33.tar.gz
[root@Web-175 opt]# mv nginx-0.8.33 nginx5
[root@Web-175 opt]# cd nginx5
实现基于 Cookie 的 Session Sticky 的功能
patch -p0 < /opt/nginx_upstream_jvm_route/jvm_route.patch
编译安装nginx
[root@Web-175 nginx5]# ./configure --prefix=/opt/nginx6--with-http_stub_status_module --with-pcre=/opt/pcre-7.6--add-module=../nginx_upstream_jvm_route/ --with-openssl=/usr/bin/openssl
[root@Web-175 nginx5]# make && make install
为了方便,直接可以拷贝174或176上的nginx.conf的配置文件修改下代理转发的端口即可.
[root@Web-175 nginx5]# catnginx6/conf/nginx.conf
user nobody;
worker_processes 4;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
worker_rlimit_nofile 51200;
events {
use epoll;
worker_connections 51200;
}
http {
include mime.types;
default_type application/octet-stream;
# limit_zone one $binary_remote_addr 10m;
server_names_hash_bucket_size 256;
client_header_buffer_size 256k;
large_client_header_buffers 4 256k;
client_max_body_size200m;
client_body_buffer_size 256k;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
send_timeout 3m;
keepalive_timeout 120;
server_tokens off;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-Javascripttext/css application/xml text/jsp;
gzip_vary on;
#proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $http_x_forwarded_for;
proxy_set_header X-Forwarded-For$proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
# proxy_buffers 32 4k;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
proxy_temp_path/opt/proxy_temp_path;
proxy_cache_path/opt/proxy_cache_path levels=1:2 keys_zone=cache_one:500m inactive=1dmax_size=30g;
# access_log logs/access.log main;
#sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
#keepalive_timeout 65;
#gzip on;
upstream {
server 127.0.0.1:9080;
ip_hash;
}
server {
listen 192.168.8.175:80;
server_name localhost 192.168.8.175;
# charset GBK;
#charset UTF-8;
access_log logs/access_linuxidc.log main;
if ($host ~linuxidc.com){
rewrite ^(.*)$1 permanent;
}
if ($host ~9h.com){
rewrite ^(.*)$1 permanent;
}
location ^~/zhuanti/ {
rewrite/zhuanti/(.*).html /html/zhuanti/$1.jsp;
}
location ^~/html/article/{
rewrite/html/article/(\d+)/(\d+)/(\d+)/(.*)\.html$ /wineCulture/detail-$1$2$3$4.shtml;
}
location / {
proxy_pass ;
proxy_set_header X-Real-IP $http_x_forwarded_for;
index index.html index.shtmlindex.jsp login.jsp index.htm;
#proxy_redirect off;
}
location ~^/static/ {
root /opt/newWebshop/;
access_log on;
expires 12h;
}
location ~^/re- {
proxy_pass ;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location ~^/pi- {
proxy_pass ;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location ~^/wineCulture/?$ {
rewrite^/wineCulture/?$ /wineCulture/content_cultureIndex.shtml;
}
location ~^/wineCulture/zuixinjiushili-(\d+)/?$ {
rewrite/wineCulture/zuixinjiushili-(\d+)/? /wineCulture/content_showArticleList.shtml?more=3&page=$1 last;
}
location ~^/wineCulture/hongjiuyujiankang-(\d+)/?$ {
rewrite/wineCulture/hongjiuyujiankang-(\d+)/? /wineCulture/content_showArticleList.shtml?page=$1&pageSize=9&more=5&seek=last;
}
location ~^/wineCulture/jiuyoutianxia-(\d+)/?$ {
rewrite/wineCulture/jiuyoutianxia-(\d+)/? /wineCulture/content_showArticleList.shtml?page=$1&pageSize=9&more=6&seek=last;
}
location~^/wineCulture/hongjiuyishu-(\d+)/?$ {
rewrite/wineCulture/hongjiuyishu-(\d+)/? /wineCulture/content_showArticleList.shtml?page=$1&pageSize=9&more=7&seek=last;
}
location~^/wineCulture/mingjiazhuanlan-(\d+)/?$ {
rewrite/wineCulture/mingjiazhuanlan-(\d+)/? /wineCulture/content_showArticleList.shtml?page=$1&pageSize=9&more=8&seek=last;
}
location ~^/wineCulture/hongjiutouzi-(\d+)/?$ {
rewrite/wineCulture/hongjiutouzi-(\d+)/? /wineCulture/content_showArticleList.shtml?page=$1&pageSize=9&more=11&seek=last;
}
location ~^/wineCulture/hongjiumeishi-(\d+)/?$ {
rewrite/wineCulture/hongjiumeishi-(\d+)/? /wineCulture/content_showArticleList.shtml?page=$1&pageSize=9&more=13&seek=last;
}
location ~^/wineCulture/hongjiuzhuangyuan-(\d+)/?$ {
rewrite/wineCulture/hongjiuzhuangyuan-(\d+)/? /wineCulture/content_showArticleList.shtml?page=$1&pageSize=9&more=15&seek=last;
}
location ~^/wineCulture/putaojiurumen-(\d+)/?$ {
rewrite/wineCulture/putaojiurumen-(\d+)/? /wineCulture/content_showArticleList.shtml?page=$1&pageSize=9&more=19&seek=last;
}
location ~^/wineCulture/zuixinjiushili/?$ {
rewrite/wineCulture/zuixinjiushili/? /wineCulture/content_showArticleList.shtml?more=3&pageSize=9 last;
}
location ~^/wineCulture/hongjiuyujiankang/?$ {
rewrite/wineCulture/hongjiuyujiankang/? /wineCulture/content_showArticleList.shtml?more=5&pageSize=9 last;
}
location ~^/wineCulture/jiuyoutianxia/?$ {
rewrite/wineCulture/jiuyoutianxia/? /wineCulture/content_showArticleList.shtml?more=6&pageSize=9 last;
}
location ~^/wineCulture/hongjiuyishu/?$ {
rewrite/wineCulture/hongjiuyishu/? /wineCulture/content_showArticleList.shtml?more=7&pageSize=9 last;
}
location ~^/wineCulture/mingjiazhuanlan/?$ {
rewrite/wineCulture/mingjiazhuanlan/?/wineCulture/content_showArticleList.shtml?more=8&pageSize=9 last;
}
location ~^/wineCulture/hongjiutouzi/?$ {
rewrite/wineCulture/hongjiutouzi/? /wineCulture/content_showArticleList.shtml?more=11&pageSize=9 last;
}
location ~^/wineCulture/hongjiumeishi/?$ {
rewrite/wineCulture/hongjiumeishi/?/wineCulture/content_showArticleList.shtml?more=13&pageSize=9 last;
}
location ~^/wineCulture/hongjiuzhuangyuan/?$ {
rewrite/wineCulture/hongjiuzhuangyuan/?/wineCulture/content_showArticleList.shtml?more=15&pageSize=9 last;
}
location ~^/wineCulture/putaojiurumen/?$ {
rewrite/wineCulture/putaojiurumen/?/wineCulture/content_showArticleList.shtml?more=19&pageSize=9 last;
}
location ^~/html/culture{
rewrite /html/culture/cultureIndex\.html /wineCulture permanent;
}
location ~^/p-list/* {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache cache_one;
proxy_cache_valid 200 304 12h;
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For$remote_addr;
proxy_pass ;
expires 1h;
}
location ~^/wineCulture/detail-.*\.shtml {
proxy_next_upstream http_502http_504 error timeout invalid_header;
proxy_cache cache_one;
proxy_cache_valid 200 304 12h;
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass ;
expires 12h;
}
location =/wineCulture/content_cultureIndex.shtml {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache cache_one;
proxy_cache_valid 200 304 12h;
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass ;
expires 4h;
}
location =/daogou/daogou_index.shtml {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache cache_one;
proxy_cache_valid 200 304 12h;
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass ;
expires 12h;
}
location ~ .*\.(jsp|do|shtml)?$ {
proxy_pass ;
proxy_set_header X-Real-IP $http_x_forwarded_for;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
root /opt/webshop/;
access_log off;
expires 30d;
}
location ~ .*\.(js|css|htm|html)?$ {
# proxy_pass ;
# proxy_set_header X-Real-IP $remote_addr;
root /opt/webshop/;
access_log off;
expires 12h;
}
location /html {
root /opt/webshop/;
index index.html index.jsp index.shtml login.jspindex.htm;
access_log off;
expires 12h;
}
location ^~ /bg
{
return 404;
}
location ^~ /WEB-INF
{
return 404;
}
error_page 404 ;
error_page 500 502 503 504 /50x.html;
location =/50x.html {
root html;
}
server_name_in_redirect off;
}
}
注意:网站域名我经过的修改。
10.挂载旧网站和新网站数据,网站数据是通过NFS实现挂载的
#mkdir /opt/webshop
#mkdir /opt/newWebshop
#mount 192.168.8.180:/root/webshop /opt/webshop/ -o nolock
#mount 192.168.8.180:/opt/newWebshop /opt/newWebshop/ -o nolock