站点没有重定向到后端节点Nginx配置

发布于 2025-01-20 05:01:43 字数 715 浏览 0 评论 0原文

我有一个带有节点后端的React前端,但我的NGINX设置当前不起作用。我要做的是redirect https://sales.example.com/api/stats/get_customer_count/2323232 to (节点后端服务器运行 http://127.0.0.0.1.1:3000 )但是我一直在开始404错误表明找不到API路径。不确定如何解决此问题。感谢它。谢谢

 server {
   root "/home/sales/frontend/dist";
   index index.html index.htm;
   server_name sales.example.com;
   error_log /var/log/nginx/error.log;
   listen 80;

 location / {
      index index.html index.htm;
      try_files $uri $uri/ /index.html =404;
 }

 location ~* ^/api/ {
     rewrite ^/api/(.*) /$1 break;
     proxy_pass http://127.0.0.1:3000;
 }
}

I have a react frontend with a node backend but my nginx setup is currently not working. What I want to do is redirect https://sales.example.com/api/stats/get_customer_count/2323232 to http://127.0.0.1:3000/stats/get_customer_count/2323232(Node backend server runs on http://127.0.0.1:3000) but I keep getting 404 errors stating that the api path is not found. Not sure how to go about fixing this. Appreciate it. Thanks

 server {
   root "/home/sales/frontend/dist";
   index index.html index.htm;
   server_name sales.example.com;
   error_log /var/log/nginx/error.log;
   listen 80;

 location / {
      index index.html index.htm;
      try_files $uri $uri/ /index.html =404;
 }

 location ~* ^/api/ {
     rewrite ^/api/(.*) /$1 break;
     proxy_pass http://127.0.0.1:3000;
 }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

这似乎已经在这里回答了,并且由@Dayo 很好。

将其转换为您的示例,如下所示:(注意,主要区别是代理传递中的尾部斜杠)

 location ~* ^/api/ {
     proxy_pass http://127.0.0.1:3000/;
 }

但是请通读

This seems to be answered here already, and the explanation written by @Dayo is good.

Translated it to your example, it looks like this: (notice, the main difference is the tailing slash in the proxy pass)

 location ~* ^/api/ {
     proxy_pass http://127.0.0.1:3000/;
 }

But please, read through the linked answer, before copying this over.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文