如何使用ExpressJS在代理上传递会话?

时间:2015-03-28 14:43:18

标签: node.js session express nginx proxy

我的应用程序在3000上运行,我已将代理设置为从子域名中获得3000点,但会话无法在代理上运行。

我试过这个:

app.enable('trust proxy');

但它不起作用。

Nginx配置

listen 80;

server_name sub.domain.com;

location / {
    proxy_pass http://domain.com:3000/;
    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;
}

会话配置

app.use(session({
store: sessionStore,  //tell express to store session info in the Redis store
secret: 'mysecret',
key: 'emre',
saveUninitialized: false,
proxy: true,
resave: true,
maxAge: 60000

1 个答案:

答案 0 :(得分:0)