简体   繁体   English

Nginx将身份验证传递给Node js Express应用

[英]Nginx pass auth to Node js Express app

I run an Express js page driven heavily by socket.io but I'm planning to setup an Nginx instance (proxy-ing the node js app) to develop the rest of the website. 我运行由socket.io驱动的Express js页面,但我打算设置一个Nginx实例(代理node js应用)来开发网站的其余部分。

If a user is authenticated in Nginx how do I pass the credentials to the express js app? 如果用户在Nginx中通过了身份验证,如何将凭据传递给express js应用程序? Can I share a cookie, or a session? 我可以共享一个cookie或一个会话吗? Also take into consideration storing data in Redis. 还应考虑在Redis中存储数据。 What's the best way of handling this? 处理此问题的最佳方法是什么?

If you use cookies to remember authentication, they will be automatically passed to Node by Nginx along with the rest of the request, with the proxy_pass directive. 如果您使用cookie来记住身份验证,则它们将通过proxy_pass指令由Nginx随请求的其余部分自动传递给Node。

If you are talking about Basic Auth (user is not strictly speaking "authenticated to Nginx" but Nginx will not serve requests without the correct credentials, you can set up custom headers when you pass requests to Node with the proxy_set_header directive, to tell Node who is authenticated. 如果您谈论的是基本身份验证(严格来说,用户并不是在“经过Nginx身份验证”,但是如果没有正确的凭据,Nginx不会提供请求,则可以在使用proxy_set_header指令将请求传递给Node时设置自定义标头,以告诉Node已认证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM