My use case requires nginx to rewrite the target url, converting the last segment of the request uri to the target service port which is accessed by a wireguard vpn. This next config version works fine. That is, my backend hosted app is published ok, but the auth_request directive is ignored =>
location /publish {
auth_request /auth;
rewrite ^/publish/([0-9]+) http://10.11.2.3:$1;
proxy_http_version 1.1;
}
I've proven the auth service is working fine. I'm stuck trying to resolve the target url which requires a port but no path.
location ~ ^/publish/([0-9]+)$ {
auth_request /auth;
proxy_pass http://10.11.2.3:$1/;
proxy_http_version 1.1;
}
This config fails because my backend service rejects the trailing slash. Error log =>
(111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: api.myservice.com, request: "GET /publish/5500 HTTP/1.1", upstream: "http://10.11.2.3:5500/"
If change the above config to proxy_pass http://10.11.2.3:$1;
then, as expected, the full uri path is appended. Error detail => upsteam: http://10.11.2.3:5500/publish/5500
I've also tried combining rewrite with break followed by proxy_pass =>
location /publish/ {
auth_request /auth;
rewrite ^/publish/([0-9]+)$ $1 break;
proxy_pass http://10.11.2.3:$1;
proxy_http_version 1.1;
}
This almost works except that the numeric uri is appended because I can't apply a trailing slash on the proxy_pass url. Error log =>
(111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: api.myservice.com, request: "GET /publish/5500 HTTP/1.1", upstream: "http://10.11.2.3:55005500"
Any ideas? proxy_redirect?