Proxy_pass destination set by request custom header

Hello,

location ~ ^/api/v(\d)/foo/bar/(.*) {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_max_temp_file_size 0;
proxy_pass
http://$http_x_destination_host:$http_x_destination_port/$uri;
}

What I’m looking for is to have X-Destination-Host and
X-Destination-Port contaning the exact host where to proxy_pass.
Since currently it doesn’t seem to get picked up I would like to ask if
is this appear correct (not counting security implications).

Thanks.

Posted at Nginx Forum: