【问题标题】:Node Express session not working on live server/productionNode Express 会话无法在实时服务器/生产环境中运行
【发布时间】:2021-10-09 19:34:19
【问题描述】:

会话不是在实时服务器/生产中工作,而是在本地工作
下面是我的 app.js 配置

app.enable('trust proxy',true);
app.use(cookieParser());
app.use(sessions({
    secret: "thisismysecrctekeyfhrgfgrfrty84fwir767",
    saveUninitialized:true,
    cookie: { maxAge: twoDay,secure:false },
    resave: false 
}));

secure:false secure:true 我都试过了
下面是我的 Nginx 配置

server {
    listen 8088;
    location / {
        proxy_pass http://127.0.0.1:5001;
        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_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

【问题讨论】:

    标签: node.js express express-session


    【解决方案1】:

    尝试添加代理:在会话配置中为 true,如下所示

    app.enable('trust proxy',true);
    app.use(cookieParser());
    app.use(sessions({
       proxy: true,
       secret: "thisismysecrctekeyfhrgfgrfrty84fwir767",
       saveUninitialized:true,
       cookie: { maxAge: twoDay,secure:false },
       resave: false 
    }));
    

    【讨论】:

      猜你喜欢
      • 2019-11-10
      • 2023-01-28
      • 2020-09-20
      • 2018-10-16
      • 1970-01-01
      • 2016-03-03
      • 1970-01-01
      • 1970-01-01
      • 2015-09-28
      相关资源
      最近更新 更多