2 zcy1222 zcy1222 于 2016.05.11 14:47 提问

nginx+tomcat session 丢失

nginx tomcat memcached
现在公司内部有2台web 服务器 49 和45
49安装了 nginx 2个tomcat memcached 45安装了 tomcat

如果把45服务器关闭掉 49的2个tomcat可以完成负载 但是把45的tomcat 启动起来
如果请求在2台服务器里 相互跳转 session 就会丢失 页面上面打印session id 也是
跳转一次 就变一次
但是 我同样的配置 在阿里云的2台服务器上面 又不会有这个问题 就是公司内部出问题的 公司内部2个服务器 是通过交换机连接在一起的

下面是nginx的配置文件
[root@localhost conf]# cat nginx.conf

user root;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
#                  '$status $body_bytes_sent "$http_referer" '
#                  '"$http_user_agent" "$http_x_forwarded_for"';

#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;
upstream 365hospital{
    server 192.168.31.49:8001 weight=5;
    server 192.168.31.45:8001 weight=5;
    jvm_route $cookie_JSESSIONID|sessionid reverse;
    }
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        proxy_pass http://365hospital;
        proxy_redirect default;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        add_header From 192.168.31.49;
        proxy_cookie_path /ROOT/ /;
        proxy_cookie_path /ROOT /;
        proxy_set_header Cookie $http_cookie;

    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}


# HTTPS server
#
#server {
#    listen       443 ssl;
#    server_name  localhost;

#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;

#    ssl_session_cache    shared:SSL:1m;
#    ssl_session_timeout  5m;

#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers  on;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

}

2个回答

CSDNXIAOC
CSDNXIAOC   2016.05.11 14:52

location / {
    proxy_pass: http://localhost:8080/abcde/
    proxy_cookie_path : /abcde/ /                   //一定需要,否则session出现问题

}......
答案就在这里:nginx tomcat session丢失
----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。

silehaixianghuirenj
silehaixianghuirenj   2016.10.08 01:22

omcat memcached 45安装了 tomcat
如果把45服务器关闭掉 49的2个tomcat可以完成负载 但是把45的tomcat 启动起来
如果请求在2台服务器里 相互跳转 session 就会丢失 页面上面打印session id 也是
跳转一次 就变一次
但是 我同样的配置 在阿里云的2台服务器上面 又不会有这个问题 就是公司内部出问题的 公司内部2个服务器 是通过交换机连接在一起的
下面是nginx的配置文件
[root@localhost conf]# cat nginx.conf
user root;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local]

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!