首页 > 代码库 > ubuntu 12.04.4 安装nginx部署session sticky

ubuntu 12.04.4 安装nginx部署session sticky

1,安装依赖的库和包,否则编译会报错

apt-get  install gcc  libpcre3 libpcre3-dev openssl libssl-dev make

2,下载附件中的nginx-1.8.1.tar.gz 及nginx-sticky-module-1.1.tar.gz

备注:

nginx-sticky-module-1.1模块在附件中,下载附件后,重命名

mv aa.txt nginx-sticky-module-1.1.tar.gz

mv nginx-1.8.1.txt nginx-1.8.1.tar.gz

tar xf nginx-1.8.1.tar.gz

mkdir /usr/local/nginx-sticky-module-1.1/

tar xf nginx-sticky-module-1.1.tar.gz  -C /usr/local/nginx-sticky-module-1.1/

cd nginx-1.8.1/

3,编译安装nginx

./configure --prefix=/usr/local/nginx-1.8.1 --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=/usr/local/nginx-sticky-module-1.1/nginx-sticky-module-1.1

会报错,根据错误提示修改文件(参考http://tenderrain.blog.51cto.com/9202912/1880880)

vim /usr/local/nginx-sticky-module-1.1/nginx-sticky-module-1.1/ngx_http_sticky_misc.c +281

make 

make install

4,配置nginx.conf

cd /usr/local/nginx-1.8.1/conf

cat nginx.conf 内容如下:

worker_processes  5;

events {

    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"‘;

    sendfile        on;

    keepalive_timeout  65;

    map $cookie_jsessionid $route_cookie {

        ~.+\.(?P<route>\w+)$ $route;

    }

    map $request_uri $route_uri {

        ~jsessionid=.+\.(?P<route>\w+)$ $route;

    }

    upstream jiracluster {

        server 10.32.115.91:8090;

        server 10.32.115.92:8090;

        sticky;

    }



server {

        listen 80;

        server_name 10.32.116.28;

        location / {

            proxy_set_header Host $host;

            proxy_set_header X-Real-IP $remote_addr;

            proxy_pass http://jiracluster;

        }


        error_log /tmp/error.log;

        access_log /tmp/access.log;

    }



}

5,检测语法,启动nginx

/usr/local/nginx-1.8.1/sbin/nginx  -t

/usr/local/nginx-1.8.1/sbin/nginx 

/usr/local/nginx-1.8.1/sbin/nginx  -t

/usr/local/nginx-1.8.1/sbin/nginx  -s reload




其实session持久化就nginx本身而言是有三种方式的

cookie

route

learn

http://nginx.org/en/docs/http/ngx_http_upstream_module.html

http://blog.csdn.net/agangdi/article/details/41087921

ubuntu 12.04.4 安装nginx部署session sticky