CAUSE
iisnode 将来自 IIS 的请求代理到运行 Express 的节点应用程序。 ssl 连接在 IIS 处终止,并且您的节点应用程序收到 http 请求。当应用程序需要通过安全连接进行 Cookie 时,cookie会话 https://github.com/expressjs/cookie-session and 快速会话 https://github.com/expressjs/session不会设置cookie。
解决
您需要告诉 Express,当出现以下情况时它可以信任代理:x-forwarded-proto
标头设置为“https”。
您可以通过添加 proxy: true config 来做到这一点
app.use(express.session({
proxy : true,
secret: 'your-secret-key',
cookie: {
secure: true
}
}));
或者你可以告诉 Express 在全局范围内信任代理:
app.set('trust proxy', 1)
还设置了enableXFF
在你的 web.config 中设置为 true。它使iisnode添加x-forwarded-proto
(and x-forwarded-for
) 向 Express 应用程序请求标头。
<configuration>
<system.webServer>
<!-- ... -->
<iisnode enableXFF="true" />
</system.webServer>
</configuration>
先决条件
iisnode 至少需要版本 0.2.11 才能具有enableXFF
配置添加x-forwarded-proto
请求 HTTP 标头。您可以通过查看您的 iisnode 的属性来检查您拥有的 iisnode 版本iisnode.dll
文件可能安装在C:\Program Files\iisnode
。如果它here。安装后它会告诉你需要重新启动服务器。我可以告诉你iisreset
命令(在提升的命令框中)就足够了。