Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

确保 Express.js res.redirect 不会被改回后端项目所在域名 #95

Closed
Dream4ever opened this issue Sep 25, 2020 · 0 comments
Closed
Labels
Back-end Where data really come and go

Comments

@Dream4ever
Copy link
Owner

Dream4ever commented Sep 25, 2020

具体流程

目前出现的问题,是在开发后端项目时,Express.js 中 res.redirect 如果要将用户重定向至其他域名下的网址会失败。

比如当前的后端项目在域名 a.com 下,res.redirect 要将用户重定向至 b.com/abc 这个 URL,但是在浏览器中最后的重定向结果,发现被重定向到了 a.com/abc,也就是重定向指令中的域名被改回后端项目所在域名了。

在 Express.js 中输出 res._header,确认 Location 的确是 b.com/abc,也就是后端程序部分是没有问题的,那问题很可能就出在 IIS 上。

于是 Google iis change http header location domain 这组关键词,果然在第一页的 Stack Overflow 链接中看到了解决方案:IIS reverse proxy interfering with redirect location header,原来是 IIS 中的 Application Request Routing(ARR)模块搞的鬼。

现在要解决这个问题就很简单了,打开 IIS 管理器,点击当前服务器名称(就在“起始页”几个字下面),然后点击右侧的 Application Request Routing Cache → Server Proxy Settings,取消勾选“Reverse rewrite host in response headers”,OK,大功告成!

@Dream4ever Dream4ever added the Back-end Where data really come and go label Sep 25, 2020
@Dream4ever Dream4ever changed the title 确保 Express.js res.redirect 重定向至其他域名下的 URL 确保 Express.js res.redirect 域名不会被改回后端项目所在域名 Sep 25, 2020
@Dream4ever Dream4ever changed the title 确保 Express.js res.redirect 域名不会被改回后端项目所在域名 确保 Express.js res.redirect 不会被改回后端项目所在域名 Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Back-end Where data really come and go
Projects
None yet
Development

No branches or pull requests

1 participant