我需要为某些特定位置设置 proxy_pass。
在本地 react 我正在使用代理中间件,我的配置看起来像这样
app.use(
"/firebase",
createProxyMiddleware({
target: "https://firebasestorage.googleapis.com/v0/b/poplco.appspot.com/o/",
pathRewrite: { "^/firebase": "/" },
headers: { "X-Forwarded-Prefix": "/" },
changeOrigin: true,
}),
);
当我调用这个时fetch(`/firebase/logos%2F${profile.generalSettingsData[3]}?alt=media`)
它完美地工作。但是对于生产,我使用带有 nginx 的 ubuntu 服务器并尝试设置位置规则。为了这
我试过了
location /firebase {
proxy_pass https://firebasestorage.googleapis.com/v0/b/poplco.appspot.com/o/;
}
当然这是行不通的。正如我所见,我应该设置重写规则以动态处理来自我的请求的路径参数,因为文件名正在动态更改路径参数。有人有什么想法吗?
最佳答案
问题已解决。最终代码
正面
axios({
baseURL: "/v0",
url: `/b/poplco.appspot.com/o/logos%2F${profile.generalSettingsData[3]}`,
method: "GET",
responseType: "blob",
})
.then((res) => {
convertBlobToBase64(res.data)
.then((base64) => setImage(base64))
.catch((error) => console.log(error));
})
.catch((err) => console.log("error", { ...err }));
}
和 nginx location /v0/ {
resolver 8.8.8.8;
proxy_pass https://firebasestorage.googleapis.com$request_uri?alt=media;
}
nginx 的主要问题在于解析器 8.8.8.8。即使我在 nginx 日志中看到完全正确重写,我也会收到错误 502。经过详细研究日志后,我发现了下一个错误 除此之外,我还遇到了很多问题
关于ubuntu - 在 ubuntu 服务器上设置 nginx proxy_pass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68088128/