Skip to content

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

@Dream4ever

Description

@Dream4ever

具体流程

目前出现的问题,是在开发后端项目时,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,大功告成!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Back-endWhere data really come and go

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions