带有Passport NodeJ的集群 [英] Cluster with Passport NodeJs
问题描述
在我们的应用程序中,我们使用Passport中间件(localStrategy,会话存储在MongoStore中)。我们决定使用群集来加速和简化服务器。
问题是更改之后,护照始终处于未授权状态。
是否可以将护照(localStrategy)与群集一起使用?
In our application, we use a Passport middleware (localStrategy, sessions are stored in a MongoStore). We decided to use Clusters in order to speed up and ease on a server. The problem is that after this change, passport always is in "not authorized" state. Is it possible to use passport (localStrategy) with clustering?
推荐答案
在内存中存储会话数据。使用群集,护照可以将数据存储在群集中,而其他请求则由其他群集处理。您必须使用会话存储。我建议使用 connect-redis
Passport store session data in memory. With Clustering, It is possible for passport to store data in a cluster and other requests handle by other clusters. You must use a session store. I recommend using connect-redis
这些链接也很有帮助:
1- > https://blog.risingstack.com/node-hero-node-js-authentication-passport-js/
2- 将护照和OAuth与connect-redis结合使用
3- https://afshinm.name/2014/06/26/using-redis-as-session-store-for-expressjs-passportjs-settings/
4- https://www.airpair.com/express/posts/expressjs-and-passportjs-sessions-deep-潜水
更新
对于MongoDb,请阅读以下链接
For MongoDb read these links
2-How can I manage sessions with Passport JS for some routes using express?
这篇关于带有Passport NodeJ的集群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!