码迷,mamicode.com
首页 > 其他好文 > 详细

tengine-1.5.2配置session_sticky后不返回session cookie问题解决

时间:2015-07-23 14:11:58      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:tengine nginx session sticky

昨天给公司tengine(1.5.2版本)反向代理的后端集群新增了一个tomcat节点,并在负载均衡集群中加入session_sticky指令以实现客户端会话保持,这时坑爹的问题出现了,客户端访问反向代理时竟然不返回session cookie,导致每次请求连接时sessionid都被重新刷新而无法通过登录。对此问题进行多次谷百,review tengine官方的email列表,尝试各种各样的配置,折腾了一天均未找到解决方法,只在官方提供的1.5.0版本changelog中看到了已经对此问题进行的修复:

Tengine-1.5.0 [2013-07-31]

  • Bugfix:修复session_sticky模块在某些情况下没有发出session cookie的问题 [dinic]

    http://tengine.taobao.org/changelog_cn.html#1_5_2

最后干脆直接下载了最新的2.1.0版本重新编译安装,在相同的配置下问题得以解决,特发此贴以免后来人走相同的弯路。


tengine配置如下:

worker_processes  1;
events {
    worker_connections  1024;
}
    
dso {
    load ngx_http_upstream_session_sticky_module.so;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    upstream tomcatcluster {
        session_sticky cookie=routerc domain=test.domain.net mode=insert fallback=on option=indirect;
        server 10.1.12.53:9083 max_fails=10 fail_timeout=10s;
        server 10.1.12.56:9083 max_fails=10 fail_timeout=10s;
        check interval=500 rise=2 fall=5 timeout=3000 type=tcp;
    }
    server {
        listen       80;
        server_name  localhost;
        location / {
           session_sticky_hide_cookie upstream=tomcatcluster;
           proxy_pass http://tomcatcluster;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

加载模块如下:

[root@01web006 conf]# ../sbin/nginx -m
Tengine version: Tengine/1.5.2 (nginx/1.2.9)
loaded modules:
    ngx_core_module (static)
    ngx_errlog_module (static)
    ngx_conf_module (static)
    ngx_dso_module (static)
    ngx_syslog_module (static)
    ngx_events_module (static)
    ngx_event_core_module (static)
    ngx_epoll_module (static)
    ngx_procs_module (static)
    ngx_proc_core_module (static)
    ngx_openssl_module (static)
    ngx_regex_module (static)
    ngx_http_module (static)
    ngx_http_core_module (static)
    ngx_http_log_module (static)
    ngx_http_upstream_module (static)
    ngx_http_static_module (static)
    ngx_http_gzip_static_module (static)
    ngx_http_autoindex_module (static)
    ngx_http_index_module (static)
    ngx_http_concat_module (static)
    ngx_http_auth_basic_module (static)
    ngx_http_access_module (static)
    ngx_http_geo_module (static)
    ngx_http_map_module (static)
    ngx_http_split_clients_module (static)
    ngx_http_referer_module (static)
    ngx_http_rewrite_module (static)
    ngx_http_ssl_module (static)
    ngx_http_proxy_module (static)
    ngx_http_fastcgi_module (static)
    ngx_http_uwsgi_module (static)
    ngx_http_scgi_module (static)
    ngx_http_memcached_module (static)
    ngx_http_empty_gif_module (static)
    ngx_http_browser_module (static)
    ngx_http_user_agent_module (static)
    ngx_http_upstream_ip_hash_module (static)
    ngx_http_upstream_consistent_hash_module (static)
    ngx_http_upstream_check_module (static)
    ngx_http_upstream_least_conn_module (static)
    ngx_http_upstream_keepalive_module (static)
    ngx_http_upstream_session_sticky_module (shared, 3.1)
    ngx_http_stub_status_module (static)
    ngx_http_write_filter_module (static)
    ngx_http_header_filter_module (static)
    ngx_http_chunked_filter_module (static)
    ngx_http_range_header_filter_module (static)
    ngx_http_gzip_filter_module (static)
    ngx_http_postpone_filter_module (static)
    ngx_http_ssi_filter_module (static)
    ngx_http_charset_filter_module (static)
    ngx_http_userid_filter_module (static)
    ngx_http_footer_filter_module (static)
    ngx_http_trim_filter_module (static)
    ngx_http_headers_filter_module (static)
    ngx_http_copy_filter_module (static)
    ngx_http_range_body_filter_module (static)
    ngx_http_not_modified_filter_module (static)


1.5.2版本下:

[root@01web006 conf]# curl -I http://127.0.0.1
HTTP/1.1 200 OK
Server: Tengine/1.5.2
Date: Thu, 23 Jul 2015 01:32:49 GMT
Content-Type: text/html;charset=UTF-8
Content-Length: 6957
Connection: keep-alive
Set-Cookie: JSESSIONID=D633A39F35AA4A8BE1429BD12C2CDC8D; Path=/; HttpOnly
Set-Cookie: _site=1; Path=/
Content-Language: en-US

curl结果并无返回session cookie(这里配置的cookie名称为routerc)


2.1.0版本下:

[root@01web006 conf]# curl -I http://127.0.0.1
HTTP/1.1 200 OK
Server: Tengine/2.1.0
Date: Thu, 23 Jul 2015 02:42:39 GMT
Content-Type: text/html;charset=UTF-8
Content-Length: 6957
Connection: keep-alive
Set-Cookie: JSESSIONID=9D04A1390FF849DC44643BFAAC1DE206; Path=/; HttpOnly
Set-Cookie: _site=1; Path=/
Content-Language: en-US
Set-Cookie: routerc=d635956645d98c4834fa077076767949;Domain=test.domain.net;Path=/

正常返回"Set-Cookie: routerc=d635956645d98c4834fa077076767949;Domain=test.bingodu.net;Path=/"

tengine-1.5.2配置session_sticky后不返回session cookie问题解决

标签:tengine nginx session sticky

原文地址:http://978538.blog.51cto.com/968538/1677470

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!