To fix this issue, you will need to update the proxy_pass directive to include the full URL path in the proxied request. This can be done by using the $request_uri variable, which contains the full URL path of the incoming request.
Here is an example of how the updated proxy_pass directive might look:
proxy_pass http://127.0.0.1:$1$request_uri;
This will pass the request to the local port, along with the full URL path of the incoming request. So a request to /ips/23950/xyz will be proxied to http://127.0.0.1:23950/xyz, which should allow the request to be handled correctly by the local server.
It's also worth noting that the location block containing the proxy_pass directive should be the only block inside the location /ips block. This is because the location blocks are processed in order, and the return 404 statement in the outer location block will prevent any requests that match the inner location block from being processed. So you will need to move the return 404 statement inside the location block that matches the URLs with port numbers, and change it to return 403 or some other error code that indicates that the requested URL is not allowed.
Here is an example of how the updated configuration might look:
location ~ ^/ips/([0-9]+) {
proxy_redirect off;
proxy_pass http://127.0.0.1:$1$request_uri;
proxy_http_version 1.1;