负载均衡使用nginx sticky实现session共享

栏目: 服务器 · Nginx · 发布时间: 6年前

内容简介:nginx-sticky-module第三方模块主要用于基于cookie实现会话保持。nginx sticky 模块工作流程图

nginx-sticky-module第三方模块主要用于基于cookie实现会话保持。

nginx sticky 模块工作流程图

负载均衡使用nginx sticky实现session共享

下载nginx sticky

安装nginx+stiky

# wget http://nginx-sticky-module.googlecode.com/files/nginx-sticky-module-1.1.tar.gz
# tar -xzvf nginx-sticky-module-1.1.tar.gz
# wget http://nginx.org/download/nginx-1.8.1.tar.gz
# tar -xzvf nginx-1.8.1.tar.gz
# cd nginx-1.8.1
# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=../nginx-sticky-module-1.1
# make
# make install

执行./configure的过程中可能会遇到以下错误:

./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using –without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using –with-pcre= option.

执行该命令解决:

yum -y install pcre-devel

./configure: error: SSL modules require the OpenSSL library.

You can either do not enable the modules, or install the OpenSSL library

into the system, or build the OpenSSL library statically from the source

with nginx by using –with-openssl= option.

执行该命令解决:

yum -y install openssl openssl-devel

在执行make的时候会报错:

../nginx-sticky-module-1.1/ngx_http_sticky_misc.c:281:2: error: passing argument 2 of ‘ngx_sock_ntop’ makes integer from pointer without a cast [-Werror]

digest->len = ngx_sock_ntop(in, digest->data, len, 1);

解决办法:

cd ../nginx-sticky-module-1.1
vim ngx_http_sticky_misc.c
将281行的digest->len = ngx_sock_ntop(in, digest->data, len, 1);改成
digest->len = ngx_sock_ntop(in, sizeof(struct sockaddr_in), digest->data, len, 1);

配置nginx sticky

upstream dispatch {
    sticky;
    server 192.168.100.100:8080;
    server 192.168.100.102:8080;
}
server {
        listen       80;
        server_name  abswolf.com;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
                proxy_redirect off;
                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://dispatch;
        }
    }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

平台转型

平台转型

陈威如、王诗一、余卓轩(统筹) / 中信出版社 / 2016-1-10 / 58

《平台战略》续篇,陈威如等关于企业平台转型最新力作! 平台带来的商业革命已改写了现在及未来的企业生存规则,而这股浪潮已经从互联网行业漫延到了其他多种行业之中!如果说,过去10 年是平台商业模式在互联网行业的爆发期,那未来10 年,将是平台商业模式在传统行业转型应用上的黄金时代。 平台思维不再是互联网行业的专用词,它可以用来解构价值链,可以被运用到组织架构的设计中,更能够帮助企业升级竞争......一起来看看 《平台转型》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

html转js在线工具
html转js在线工具

html转js在线工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具