nginx 代理后面的 glassfish 中的持久会话
Persistent session in glassfish behind nginx proxy
我是 运行 nginx 代理(解析域)后面的 glassfish 网络服务器。我想在 Web 服务器上存储 @SessionScoped 数据。
我的问题是,nginx 每次连接到 glassfish 时都会打开一个新会话,并且该会话绝不会连接到客户端。客户端本身在 nginx 上有一个活动会话。
Glassfish 似乎意识到了一个事实,即处理会话的方式有问题。它操纵应用程序中的链接以保持会话完整:
“.../ProxyTest/page2.jsf;jsessionid=4372da9b75a2043875c73b12f998”
如果我直接连接到网络服务器(没有代理),它不会这样做
这种行为对我来说是完全不能接受的,我需要那种操纵消失,但仍然有会话。
我想为每个通过代理连接到它的用户在 glassfish 上建立一个单独的持久会话,而不必在 url.
中传递 sessionID
nginx确实设置了cookie,但是浏览器没有发回。我假设 cookie 的格式正确:
Set-Cookie:"JSESSIONID=84c5e4e43538da045cc1d8f2a629; Path=/ProxyTest; HttpOnly"
我的 nginx 设置:
服务器 {
听80;
server_name www.abc.ch;
location / {
proxy_set_header customer abc;
access_log off;
proxy_pass http://127.0.0.1:8081/ProxyTest/;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
}
}
server {
listen 80;
server_name www.onlineshop.ch;
location / {
proxy_set_header customer onlineshop;
access_log off;
proxy_pass http://127.0.0.1:8081/ProxyTest/;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
}
现在的问题是,浏览器没有发回 cookie,或者由于某种原因它没有通过服务器。在每次请求时,服务器都会生成一个新的会话 ID。确认存储在 @SessionScoped bean 中的数据丢失了。
如果您 post 您的 NGINX 代理配置,它会有所帮助。基本的反向代理配置如下所示:
...
http {
....
server {
listen 80;
server_name www.yourdomain.com;
location / {
access_log off;
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
...
}
....
}
}
我是 运行 nginx 代理(解析域)后面的 glassfish 网络服务器。我想在 Web 服务器上存储 @SessionScoped 数据。 我的问题是,nginx 每次连接到 glassfish 时都会打开一个新会话,并且该会话绝不会连接到客户端。客户端本身在 nginx 上有一个活动会话。
Glassfish 似乎意识到了一个事实,即处理会话的方式有问题。它操纵应用程序中的链接以保持会话完整: “.../ProxyTest/page2.jsf;jsessionid=4372da9b75a2043875c73b12f998” 如果我直接连接到网络服务器(没有代理),它不会这样做 这种行为对我来说是完全不能接受的,我需要那种操纵消失,但仍然有会话。
我想为每个通过代理连接到它的用户在 glassfish 上建立一个单独的持久会话,而不必在 url.
中传递 sessionIDnginx确实设置了cookie,但是浏览器没有发回。我假设 cookie 的格式正确:
Set-Cookie:"JSESSIONID=84c5e4e43538da045cc1d8f2a629; Path=/ProxyTest; HttpOnly"
我的 nginx 设置: 服务器 { 听80; server_name www.abc.ch;
location / {
proxy_set_header customer abc;
access_log off;
proxy_pass http://127.0.0.1:8081/ProxyTest/;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
}
}
server {
listen 80;
server_name www.onlineshop.ch;
location / {
proxy_set_header customer onlineshop;
access_log off;
proxy_pass http://127.0.0.1:8081/ProxyTest/;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
}
现在的问题是,浏览器没有发回 cookie,或者由于某种原因它没有通过服务器。在每次请求时,服务器都会生成一个新的会话 ID。确认存储在 @SessionScoped bean 中的数据丢失了。
如果您 post 您的 NGINX 代理配置,它会有所帮助。基本的反向代理配置如下所示:
...
http {
....
server {
listen 80;
server_name www.yourdomain.com;
location / {
access_log off;
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
...
}
....
}
}