繁体   English   中英

nginx 中的 proxy_pass 似乎被跳过并且 REACT axios POST 调用到了错误的地址

[英]proxy_pass in nginx seems to be skipped and REACT axios POST call went to wrong address

我是 nginx 的新手,一直在寻找解决方案,但无济于事。 在 nginx.conf 文件中,我有类似的内容:

server {
    location /core-api {
      proxy_pass http://backend.companyname.com/core-api;   
    }

    location / {
      try_files $uri$args $uri$args/ /index.html;
    }
}

在 REACT 中,我有以下代码:

  register(...args) {
    return axios.post('/core-api/register', ...args)
  }

我想要发生的是让 axios POST 调用 go 到:

http://backend.companyname.com/core-api/register

发生的事情是 POST 请求将自己降落在:

http://www.companyname.com/core-api/register

我会收到 502 错误。

你知道出了什么问题吗? 先感谢您。

我们遇到了类似的问题,后端在 AWS beanstalk 后面运行。 问题是后端将不断更改其在 DNS 后面的 IP,这会导致 nginx 出现问题。

我在一些博客中看到了这种情况并应用了下面的方法,看看它是否适合你。

server {
    location /core-api {
      set $backend 'backend.companyname.com';
      proxy_pass http://$x;   
    }

    location / {
      try_files $uri$args $uri$args/ /index.html;
    }
}

此外,如果您有 nginx+,您可以使用解析器将其移动到上游。 如果您可以提供有关后端的更多信息,那就太好了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM