I have been able to make a reverse proxy using Nginx to redirect POST requests made to the 8080 port to the 8081 port. Now, I would like to redirect them to the 8082 additionally.
events {}
http {
server {
listen 127.0.0.1:8080;
location / {
proxy_pass http://127.0.0.1:8081/;
}
location /api/ {
proxy_pass http://127.0.0.1:8082/;
}
}
}
But by doing this, I'm only receiving the requests on the 8081 port, and not on the 8082 with the /api endpoint. Also, I would like to not use any endpoint ( / ) on both reverse proxy configuration if possible.
Thanks.
I think the problem is that the server listening on port 8082 actually is receiving the traffic, but you're getting an error because the proxy is requesting /api/ rather than /, since it's literally just forwarding the request. If this actually is the problem, rewriting the request before passing it off via the proxy should do the trick.
server {
listen 127.0.0.1:8080;
location / {
proxy_pass http://127.0.0.1:8081/;
}
location /api/ {
rewrite /api/(.*) /$1 break;
proxy_pass http://127.0.0.1:8082/;
}
}
}
Unfortunately, I'm not really sure what you mean by your last sentence. Do you mean that you want the api endpoint to be reachable via the base URI as well?