I have a couple of API endpoints that I want to serve from under a single location of /api
with subpaths going to different endpoints. Specifically, I want webdis to be available at /api
and a proprietary API available at /api/mypath
.
I'm not worried about clashes with the webdis API because I am using subpaths which are unlikely to clash with redis command names, and also have full control over the design of the API to avoid clashes.
Here's the config file from my test server that I have been hacking on:
server {
listen 80;
server_name localhost;
server_name 192.168.3.90;
server_name 127.0.0.1;
location / {
root /home/me/src/phoenix/ui;
index index.html;
}
# temporary hardcoded workaround
location = /api/mypath/about {
proxy_pass http://localhost:3936/v1/about;
}
location /api {
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://localhost:7379/;
}
# tried this but it gives "not found" error
#location ^~ /api/mypath/ {
# rewrite ^/api/mypath/(.*)$ /$1 break;
# proxy_pass http://localhost:3936/v1/;
#}
#
#location ^~ /api {
# rewrite ^/api/(.*)$ /$1 break;
# proxy_pass http://localhost:7379/;
#}
}
How can I change my workaround so that any requests to /api/mypath/*
will go to the endpoint at port 3936, and everything else to port 7379?