【问题标题】:setting nginx proxy_pass on ubuntu server在 ubuntu 服务器上设置 nginx proxy_pass
【发布时间】:2021-09-06 07:37:41
【问题描述】:

我需要为某个特定位置设置 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/;
    }

当然不行。正如我所见,我应该设置重写规则以动态处理来自我的请求的路径参数,因为文件名正在动态更改路径参数。 有人有什么想法吗?

【问题讨论】:

    标签: ubuntu nginx nginx-reverse-proxy


    【解决方案1】:

    问题已解决。最终代码 正面

    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 中,但这是另一个故事,我在这一点上发现了很多问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      • 2021-08-05
      • 2016-03-10
      • 1970-01-01
      • 2018-07-26
      • 2021-04-05
      相关资源
      最近更新 更多