node.js - Tell ngix to send file from within node app with reverse proxy
问题描述
I have a node express app that is proxied by nginx. Nginx already handles most public static files, on /static
However, I have some files that need restricted access. After nginx proxies the HTTP request to my node app, on /restricted, I need to run my authorization logic and then, somehow, let nginx know that it should serve a specific file, from a directory that is not public.
I don't want to send the files directly from node as they are big and will block the main thread.
解决方案
- Generate a response from your app containing an
X-Accel-Redirect
HTTP response header which specifies a URI beginning with/restricted/
- Nginx will intercept the response and internally rewrite the URI
- Configure a
location
block containing aninternal
directive
For example:
location /restricted {
internal;
alias /path/to/files;
}
See this document for more.
推荐阅读
- google-maps - 颤振地理定位器包不检索位置
- speech-recognition - 连续语音中音素识别的隐马尔可夫模型
- css - 如何设置第一个字母的样式并应用此线性渐变动画?
- sql - 在 SQL Server 的更新语句中使用 group by 时出现语法错误
- django - 具有重复字段的行的 Django“列表”和“详细信息”视图
- apache-kafka - Spring cloud Stream Kafka:获取processor.output().send(message)的确认;
- wordpress - Woocommerce - 如果在结帐期间登录,则删除所有旧购物车物品
- react-native - React-Native/Redux-Saga:如何等待调度完成
- xamarin - TabbedPage 上的 Retap 事件
- java - 使用 Log4j 为同一类分隔日志文件