I'm trying to achieve the below in nginx:
Hit nginx on http://<nginx-host>:81/admin/metrics and have nginx proxy it to http://127.0.0.1:8001 with the /admin/metrics rewritten to /metrics. The actual proxied admin app would receive http://127.0.0.1:8001/metrics.
So, http://<nginx-host>:81/admin/metrics => http://127.0.0.1:8001/metrics, and without causing a redirect.
This is what I have so far:
#admin app
upstream admin_backend {
server 127.0.0.1:8001;
keepalive 16;
}
#host /admin paths on another port
server {
listen 81;
#pass everything to backend admin app that matches /admin/* with /admin/ removed
location ~ /admin/ {
limit_except GET HEAD POST PUT { }
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_pass http://admin_backend;
rewrite ^/admin/(.*)$ /$1 last;
}
}
This is not working. nginx is not proxying the request back to the admin app and keeps returning a 404.
What am I missing here?