维护同一域中托管的多个节点红色实例之间的会话

我通过Nginx使用单个域名在多个服务器上运行多个节点红色应用程序,例如:

server {
  server_name abc.com www.abc.com; #main website
  root /var/www/web;
  index index.html;

location /server/demo{
    proxy_pass http://xx.xxx.xx.xx:1880/server/demo; #node-red app 1
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

location /server/demo2{
    proxy_pass http://yy:yyy:yy:yy:1880/server/demo2; #node-red app 2
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

location /server/demo3{.....  #node red app 3
......
......

我不确定,但是我认为所有这些实例都共享同一个会话或cookie,因此我无法在同一浏览器/机器上登录到我的应用程序的多个实例(即使它们正在运行)不同的服务器)。如果我登录到一个节点红色的实例,然后在新选项卡中登录(如果我登录到另一个实例),我将从第一个实例退出。

例如,我无法同时登录abc.com/server/demo1和abc.com/server/demo2,但是我可以使用其IP地址http://xx.xxx.xx.xx:1880/server/demo和{ {3}}。

如果这本身就是问题所在,是否可以为Nginx中的每个位置对象设置HTTP cookie? 要么 实现此功能的更好方法?

leon197788 回答:维护同一域中托管的多个节点红色实例之间的会话

Node-RED使用默认的express-session插件,该插件默认在根路径/上设置所有cookie。

我还没有尝试过,但是看起来nginx的proxy_cookie_path指令可能能够完成您想要的操作。这些文档是here

如果我正确理解了文档,则每个实例的这样的条目都应该起作用:

location /server/demo{
    proxy_pass http://xx.xxx.xx.xx:1880/server/demo; #node-red app 1
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_cookie_path / /demo;
}

location /server/demo2{
    proxy_pass http://yy:yyy:yy:yy:1880/server/demo2; #node-red app 2
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_cookie_path / /demo2;
}
本文链接:https://www.f2er.com/3077315.html

大家都在问