【发布时间】:2023-03-04 23:41:01
【问题描述】:
我正在尝试在由 node.js 支持的 nginx 上设置授权文件访问。出于某种原因,所有示例都不适合我。我正在尝试从/data/private/files 提供文件服务
我的 nginx 配置:
...
server {
listen 4000;
server_name localhost;
location / {
proxy_pass http://127.0.0.1:3000/;
}
location /files {
root /data/private;
internal;
}
我的节点 server.js:
var http = require('http');
http.createServer(function (req, res) {
console.log(req.url);
res.end('works');
}).listen(3000);
当我请求http://localhost:4000/xyz 时,请求被正确传递到节点。当我请求http://localhost:4000/files/test.jpg 时,我只得到一个 404 并且没有任何东西传递给节点。我究竟做错了什么?当我推荐 internal 然后 test.jpg 直接由 nginx 正确提供,所以我假设路径是正确的?
我很确定我之前在某个时候有过这个工作,但是在某个不同的服务器上可能有不同的节点和 nginx 版本。尝试使用 nginx 1.6.0 和 1.2.6,节点 v0.10.21。我还添加了您在所有示例中找到的所有 proxy_set_header 和 proxy_pass 选项,但没有任何效果。我现在正在基于 Vagrant 的 Ubuntu VM 中运行它,但也不能在 Mac 上运行。
我知道我必须通过res.setHeader("X-Accel-Redirect", req.url); 设置标头,但这不是这里的问题,因为我什至没有进入可以在节点中设置所需标头的阶段。
【问题讨论】:
标签: node.js nginx x-accel-redirect