下载nginx-sticky-module包 ??链接:https://pan.baidu.com/s/1kUTuR1H? ?密码:8h3h?
?2. ? 安装ssl(如果已经安装了,就不需要安装了,sticky模块依赖这个包)
yum?install?openssl?? yum?install?openssl-devel
3、重新添加模块,编译
./configure?--prefix=/application/nginx-1.10.2?--user=www?--group=www?--with-http_stub_status_module?--with-http_ssl_module?--add-module=/data/nginx-sticky-module-1.1
make
期间会报各种错,需要修改vim /data/nginx-sticky-module-1.1/ngx_http_sticky_module.c?
第6行添加一行
#include?<nginx.h> #include?<ngx_config.h> #include?<ngx_core.h> #include?<ngx_http.h>
第332行附近
????????????????ngx_log_debug(NGX_LOG_DEBUG_HTTP,?pc->log,?0,?"[sticky/get_sticky_peer]?peer?found?at?index?%i",?selected_peer) ; #if?defined(nginx_version)?&&?nginx_version?>=?1009000 ????????????????iphp->rrp.current?=?peer; #else ????????????????iphp->rrp.current?=?iphp->selected_peer; #endif
修改 ?vim /data/nginx-sticky-module-1.1/ngx_http_sticky_misc.c 第281行
改成
????????digest->len?=?ngx_sock_ntop(in,?sizeof(struct?sockaddr_in),?digest->data,?len,?1);
保存退出
重新
./configure?--prefix=/application/nginx-1.10.2?--user=www?--group=www?--with-http_stub_status_module?--with-http_ssl_module?--add-module=/data/nginx-sticky-module-1.1
make
成功
不要再make install 不然就重新安装了nginx
4.关闭原来的nginx
killall?nginx
5. 复制编译后的二进制文件到目录
cp?/application/nginx/sbin/nginx{,.bak}???先备份cp?/data/nginx-1.10.2/objs/nginx?/application/nginx/sbin/nginx????再复制命令
6. 修改配置nginx文件,使插件sticky生效
[root@master?conf]#?vim?/application/nginx/conf/nginx.conf
在upstream中添加sticky;
http?{??
????upstream?uec_portal{??
????????#添加sticky模块后加入此配置??
????????sticky;??
????????#被代理的服务??
????????server?192.168.12.56:80;??
????????server?192.168.12.70:8080;??
????}??
??
??
????server?{??
????????#nginx监听的端口??
????????listen???????80;??
????????server_name??localhost;??
??
??
????????location?/?{??
????????????#代理??
????????????proxy_pass?http://uec_portal;??
????????}??
??
??
???}??
}?
7. 测试配置文件是否OK
[root@master?conf]#?/application/nginx/sbin/nginx?-t Enter?PEM?pass?phrase: nginx:?the?configuration?file?/application/nginx-1.10.2/conf/nginx.conf?syntax?is?ok nginx:?configuration?file?/application/nginx-1.10.2/conf/nginx.conf?test?is?successful
8.启动nginx
[root@master?conf]#?/application/nginx/sbin/nginx
9.测试。
至此session丢失问题就解决了。
原文:http://blog.51cto.com/dellinger/2048675