Nginx sticky模块实现session粘滞

简介:

注:系统已安装nginx

 

一:下载,解压nginx sticky模块。

1
2
3
# cd /usr/local/src
# wget http://nginx-sticky-module.googlecode.com/files/nginx-sticky-module-1.1.tar.gz
# tar -zxvf nginx-sticky-module-1.1.tar.gz

 

二:查看现有nginx的编译参数,加上sticky模块参数重新编译。

1
2
3
4
5
#/usr/local/nginx/sbin/nginx –V
nginx version: nginx /1 .3.14
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-54)
TLS SNI support disabled
configure arguments: --prefix= /usr/local/nginx--user =nobody --group=nobody --with-select_module --with-poll_module--with- file -aio --with-http_ssl_module --with-http_realip_module--with-http_gzip_static_module --with-http_secure_link_module--with-http_sub_module --with-http_stub_status_module--add-module= /root/nginx-http-concat/

 关闭nginx,加上sticky模块重新编译nginx(建议先备份配置文件)

1
2
3
4
# service nginx stop
# cd /usr/local/src/nginx-1.3.14
#./configure --prefix=/usr/local/nginx --user=nobody --group=nobody --with-select_module --with-poll_module --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-http_secure_link_module --with-http_sub_module --with-http_stub_status_module --add-module=/root/nginx-http-concat/ --add-module=/usr/local/src/nginx-sticky-module-1.1
# make && make install

 

三:修改配置文件,添加sticky相关参数

 在类似如下位置添加参数(红色字体)

1
2
3
4
5
6
7
vi  upstream.conf
upstream  test .com
{
    sticky;                     ---sticky
    server192.168.1.17:9082 weight=5 max_fails=2 fail_timeout=30s;
    server192.168.1.81:9082 weight=5 max_fails=2 fail_timeout=30s;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#vi web.conf
server {
        listen       9082;
        server_name *. test .com;
        access_log  /data/logs/test .com access_log;
        error_log   /data/logs/test .com.errorlog;
        set  $proxy_pass  test .com;
  
        location / {
            root   html;
            index index.html index.htm;
            proxy_set_header Host  $host:$server_port;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_pass  http: //test .com;
            add_headerCache-Control no-store;
  
                   }

 

四:启动nginx,网页测试。

1
2
3
#/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
或者 
#service nginx start










本文转自 icenycmh 51CTO博客,原文链接:http://blog.51cto.com/icenycmh/1794452,如需转载请自行联系原作者
目录
相关文章
|
应用服务中间件 nginx
Nginx安装nginx-rtmp-module模块
【2月更文挑战第4天】 nginx中的模块虽然就是类似插件的概念,但是它无法像VsCode那样轻松的安装扩展。 nginx要安装其它模块必须同时拿到nginx源代码和模块源代码,然后手动编译,将模块打到nginx中,最终生成一个名为nginx的可执行文件。
992 6
|
应用服务中间件 nginx
百度搜索:蓝易云【利用nginx内置ngx_http_mirror_module模块实现流量复制及流量放大】
以上就是使用Nginx内置 `ngx_http_mirror_module`模块实现流量复制和流量放大的简要示例。通过合理配置和利用该模块,可以实现更复杂的流量控制和调试需求。
352 1
|
负载均衡 应用服务中间件 API
Nginx:location配置模块的用法(一)
Nginx:location配置模块的用法(一)
1546 2
|
缓存 应用服务中间件 nginx
安装nginx-http-flv-module模块
本文介绍如何为Nginx安装`nginx-http-flv-module`模块。此模块基于`nginx-rtmp-module`二次开发,不仅具备原模块的所有功能,还支持HTTP-FLV播放、GOP缓存、虚拟主机等功能。安装步骤包括:确认Nginx版本、下载相应版本的Nginx与模块源码、重新编译Nginx并加入新模块、验证模块安装成功。特别注意,此模块已包含`nginx-rtmp-module`功能,无需重复编译安装。
1165 3
|
负载均衡 应用服务中间件 Linux
在Linux中,常用的 Nginx 模块有哪些,常来做什么?
在Linux中,常用的 Nginx 模块有哪些,常来做什么?
|
应用服务中间件 nginx C++
nginx的cgi模块
nginx的cgi模块
224 0
|
缓存 前端开发 应用服务中间件
Nginx:location配置模块的用法(二)
Nginx:location配置模块的用法(二)
1093 2
|
应用服务中间件 Linux nginx
FFmpeg开发笔记(四十)Nginx集成rtmp模块实现RTMP推拉流
《FFmpeg开发实战》书中介绍了如何使用FFmpeg向网络推流,简单流媒体服务器MediaMTX不适用于复杂业务。nginx-rtmp是Nginx的RTMP模块,提供基本流媒体服务。要在Linux上集成rtmp,需从官方下载nginx和nginx-rtmp-module源码,解压后在nginx目录配置并添加rtmp模块,编译安装。配置nginx.conf启用RTMP服务,监听1935端口。使用ffmpeg推流测试,如能通过VLC播放,表明nginx-rtmp运行正常。更多详情见书本。
530 0
FFmpeg开发笔记(四十)Nginx集成rtmp模块实现RTMP推拉流
|
Ubuntu 前端开发 JavaScript
如何在 Ubuntu 14.04 上为 Nginx 添加 gzip 模块
如何在 Ubuntu 14.04 上为 Nginx 添加 gzip 模块
151 0
|
Ubuntu 应用服务中间件 nginx
ubuntu编译安装nginx及安装nginx_upstream_check_module模块
以上是编译安装Nginx和安装 `nginx_upstream_check_module`模块的基本步骤。根据你的需求和环境,你可能需要进一步配置Nginx以满足特定的要求。
970 3