我通过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和http://yy:yyy:yy:yy:1880/server/demo2登录到多个实例。
如果这本身就是问题所在,是否可以为Nginx中的每个位置对象设置HTTP cookie?要么实现此功能的更好方法?
Node-RED使用默认的快速会话插件,该插件默认在根路径/
上设置所有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;
}