首页 > 解决方案 > nginx 将远程 URL 重定向到本地文件

问题描述

尝试做一些简单的事情(我认为),但在如何到达那里时遇到了困难。我是 nginx 的新手,这无济于事。我已经阅读了各种帖子以及我能找到的任何其他内容。

我想将 nginx 配置为将所有请求重定向到特定 URL 到 localhost 上的文件夹。例如,以下请求:

https://www.example.com/alpha/beta/gamma
https://www.example.com/alpha/beta/gamma/index.html
https://www.example.com/alpha/beta/gamma/assets/images/friend.png
https://www.example.com/alpha/beta/gamma/main.ce6329ef0ed8aa52d583.bundle.js

将提供以下文件:

/Users/flynn/Projects/new-ui/dist/index.html
/Users/flynn/Projects/new-ui/dist/index.html
/Users/flynn/Projects/new-ui/dist/assets/images/friend.png
/Users/flynn/Projects/new-ui/dist/main.ce6329ef0ed8aa52d583.bundle.js

对以 开头的 URL 的所有其他请求https://www.example.com都不会被重定向,而只是通过。这些请求将返回响应并设置应自动发回的 cookie。

任何帮助深表感谢。

标签: nginx

解决方案


推荐阅读