gpt4 book ai didi

node.js - 告诉 nginx 使用反向代理从 Node 应用程序内发送文件

转载 作者:太空宇宙 更新时间:2023-11-04 00:00:10 26 4
gpt4 key购买 nike

我有一个由 nginx 代理的 Node Express 应用程序。 Nginx 已经可以处理大多数公共(public)静态文件,位于 /static

但是,我有一些文件需要限制访问。在 nginx 将 HTTP 请求代理到我的 Node 应用程序后,在 /restricted 上,我需要运行我的授权逻辑,然后以某种方式让 nginx 知道它应该从非公共(public)目录提供特定文件。

我不想直接从 Node 发送文件,因为它们很大并且会阻塞主线程。

最佳答案

  • 从您的应用生成一个响应,其中包含 X-Accel-Redirect HTTP 响应 header ,该 header 指定以 /restricted/ 开头的 URI
  • Nginx 将拦截响应并在内部重写 URI
  • 配置包含 internal 指令的 location block

例如:

location /restricted {
internal;
alias /path/to/files;
}

参见this document了解更多。

关于node.js - 告诉 nginx 使用反向代理从 Node 应用程序内发送文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55149409/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com