nginx添加php模块,Nginx 添加sticky模块

1)下载nginx-sticky安装包nginx-goodies-nginx-sticky-module-ng-08a395c66e42

2)解压

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

make

错误信息:(再执行make && make install时报如下错误)

/tmp/soft/nginx-sticky-module-1.1/ngx_http_sticky_misc.c:281: error: too few arg

uments to function ‘ngx_sock_ntop’

make[1]: *** [objs/addon/nginx-sticky-module-1.1/ngx_http_sticky_misc.o] Error 1

make[1]: Leaving directory `/tmp/soft/nginx-1.6.2′

make: *** [build] Error 2

3)更改ngx_http_sticky_misc.c

ngx_http_sticky_misc

把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);

4)更改ngx_http_sticky_module.c

ngx_http_sticky_module

在#include 上一行增加

#include

在iphp->rrp.current = iphp->selected_peer; 上一行增加

#if defined(nginx_version) && nginx_version >= 1009000

iphp->rrp.current = peer;

#else

在iphp->rrp.current = iphp->selected_peer; 下一行增加

#endif

5)配置nginx

cd /usr/local/nginx/conf

vi nginx.conf

upstream webmerserServer{

sticky;

server 10.10.38.196:8018;

server 10.10.38.196:8028;

}

如果下载nginx-sticky包是nginx-sticky-module-1.1.tar.gz,不需要修改配置文件

1)./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-http_realip_module –add-module=/tmp/soft/nginx-sticky-module-1.1

2)make

3)make install

4) 查看nginx

cd /usr/local/nginx/sbin

./nginx -V

[root@slave01 sbin]# ./nginx -V

nginx version: nginx/1.10.2

built by gcc 4.1.2 20080704 (Red Hat 4.1.2-52)

built with OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008

TLS SNI support disabled

configure arguments: –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-pcre=/root/local/pcre-8.35 –add-module=/root/local/nginx-sticky

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Stickynginx的一个模块,它是基于cookie的一种nginx的负载均衡解决方案,通过分发和识别cookie,来使同一个客户端的请求落在同一台服务器上,默认标识名为route (a)客户端首次发起访问请求,nginx接收后,发现请求头没有cookie,则以轮询方式将请求分发给后端服务器。 (b)后端服务器处理完请求,将响应数据返回给nginx。 (c)此时nginx生成带route的cookie,返回给客户端。route的值与后端服务器对应,可能是明文,也可能是md5、sha1等Hash值 (d)客户端接收请求,并保存带route的cookie。 (e)当客户端下一次发送请求时,会带上route,nginx根据接收到的cookie中的route值,转发给对应的后端服务器。 其他需要注意的 (a)同一客户端的请求,有可能落在不同的后端服务器上。如果客户端启动时同时发起多个请求。由于这些请求都没带cookie,所以服务器会随机选择后端服务器,返回不同的cookie。当这些请求中的最后一个请求返回时,客户端的cookie才会稳定下来,值以最后返回的cookie为准。 (b)cookie不一定生效。由于cookie最初由服务器端下发,如果客户端禁用cookie,则cookie不会生效。 (c)客户端可能不带cookie。Android客户端发送请求时,一般不会带上所有的cookie,需要明确指定哪些cookie会带上。如果希望用sticky做负载均衡,请对Android开发说加上cookie。 (d)cookie名称不要和业务使用的cookie重名。Sticky默认的cookie名称是route,可以改成任何值。 (e)客户端发的第一个请求是不带cookie的。服务器下发的cookie,在客户端下一次请求时才能生效。 (f)Nginx sticky模块不能与ip_hash同时使用 sticky [name=route] [domain=.foo.bar] [path=/] [expires=1h] [hash=index|md5|sha1] [no_fallback] [secure] [httponly]; [name=route] 设置用来记录会话的cookie名称 [domain=.foo.bar] 设置cookie作用的域名 [path=/] 设置cookie作用的URL路径,默认根目录 [expires=1h] 设置cookie的生存期,默认不设置,浏览器关闭即失效,需要是大于1秒的值 [hash=index|md5|sha1] 设置cookie中服务器的标识是用明文还是使用md5值,默认使用md5 [no_fallback] 设置该项,当sticky的后端机器挂了以后,nginx返回502 (Bad Gateway or Proxy Error) ,而不转发到其他服务器,不建议设置 [secure] 设置启用安全的cookie,需要HTTPS支持 [httponly] 允许cookie不通过JS泄漏,没用过

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值