如何解决在 ubuntu 服务器上设置 nginx proxy_pass
我需要为某个特定位置设置 proxy_pass。 在本地反应我使用代理中间件,我的配置看起来像这样
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。在详细研究日志后,我发现了下一个错误 除此之外,我在 %2F 方面遇到了很多麻烦,nginx 编码/解码只是在 / 或 %252F 中,但这是另一回事,我在这一点上发现了很多问题
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。