0

I have a series of local services all running on different ports. I'd like to expose these services via a nginx reverse proxy. The routing patterns should follow the pattern:

  • 0.0.0.0/app -> locahost:3000
  • 0.0.0.0/api -> locahost:3001
  • 0.0.0.0/db -> locahost:3002

I've tried the following:

http {
 
    sendfile on;

    upstream app {
      server localhost:3000;
    }

    upstream api {
      server localhost:3001;
    }

    upstream db {
      server localhost:3002;
    }
 
    server {
      listen 80;
      server_name 0.0.0.0

      location / {
        proxy_pass http://app
      }

      location /api {
        proxy_pass http://api
      }

      location /db {
        proxy_pass http://db
      }
    }
}

The main issue I'm encountering at the moment is that the location is appended to the final path resulting in:

  • 0.0.0.0/db -> localhost:3002/db

I'm guessing I could use a rewrite rule, but I'm having trouble getting it right.

Vaune_
  • 1
  • 1

1 Answers1

0

You are missing the / at the end.

    location /api {
        proxy_pass http://api/
    }

From the documentation:

If proxy_pass is specified without a URI, the request URI is passed to the server in the same form as sent by a client when the original request is processed, or the full normalized request URI is passed when processing the changed URI

The same for the others.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89