0

I am using Nginx as reverse proxy to serve react application and backend api.

upstream api {
  server localhost:5000;
}




server {

        root /var/www/example.com/html;
        index index.html index.htm index.nginx-debian.html;

        server_name example.com  www.example.com;

        location / {
                try_files $uri $uri/ =404;
        }


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

// Ideally, the solution should redirect this routes to use /var/www/example.com/html/index.html
// 1. example.com/teams/1 -> would resolve into react app being served (/var/www/example.com/html/index.html)
// 2. example.com/homepage -> would resolve into react app being served (/var/www/example.com/html/index.html)
// 3. example.com/api/teams/1 -> would resolve into upstream api (localhost:5000/teams/1)

  
}

How can I achieve something like this within Nginx?

LuckyLuke
  • 1,028
  • 2
  • 14
  • 28

0 Answers0