0

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;
 }
}
Raider32
  • 11
  • 1
  • 3

1 Answers1

0

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.