ubuntu - 在 ubuntu 服务器上设置 nginx proxy_pass

标签 ubuntu nginx nginx-reverse-proxy

我需要为某些特定位置设置 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。经过详细研究日志后,我发现了下一个错误 enter image description here
除此之外,我还遇到了很多问题

关于ubuntu - 在 ubuntu 服务器上设置 nginx proxy_pass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68088128/

相关文章:

ubuntu - 将 optirun 和 g++ 设置为编译器以在 Ubuntu 中编译 OpenCL

java - 我怎么知道java jdk是否安装了

linux - 由于缺少 Build.include 文件,Ubuntu 20.04 中的 objtool 制作失败?

ssl - 通过单域使用 flynn 应用程序

带有 nuxt 和 nginx 反向代理的 laravel websocket 返回 502

php - Laravel Sqlite 数据库无法连接

html - 将 Apache Mod Rewrite 规则转换为 NGINX

nginx - 谷歌分析 4 使用 nginx 进行反向代理

docker - 带有Docker的动态Nginx代理

ruby - 用于 nginx 的 ruby​​ 中的自定义目录列表处理程序