1

I have two HTTP endpoint as follow

http://me11.example.local/api/foo

http://me11.example.local/api/boo

I want to redirect them to two different endpoints. In my config file it works for only one URL. how do I configure this for both endpoints? my Nginx config file looks as below

server {
  listen 80;
  listen [::]:80;

  server_name me11.example.local;

  location /{
   rewrite ^/api/foo / last;
   proxy_pass http:localhost:5000;
      }
 location /{
   rewrite ^/api/boo / last;
   proxy_pass http:localhost:6000;
      }
}

With this config I received the following error

duplicate location and so on

If I remove one location block it works fine but I need this to function for both endpoints.

How would I solve this issue?

Citizen
  • 1,103
  • 1
  • 10
  • 19
celcin
  • 111
  • 3

1 Answers1

-1

you can try something similar to:

server {
    listen 80;
    listen [::]:80;

    server_name me11.example.local;

    if ($request_uri = "/api/foo") {
        rewrite ^/api/foo / last;
        proxy_pass http:localhost:5000;
    }
    if ($request_uri = "/api/boo") {
        rewrite ^/api/boo / last;
        proxy_pass http:localhost:6000;
    }
}

but watch out for the if in nginx: https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/

you can check nginx.conf variables here: http://nginx.org/en/docs/varindex.html

Regards,