I have the following NGINX configuration file:
server {
server_name devices.example.org;
ssl_protocols TLSv1.2;
ssl_certificate /etc/ssl/web/example.crt;
ssl_certificate_key /etc/ssl/web/example.key;
location ~* ^/(.*)(.*)?$ {
proxy_pass http://$1.proxy.tv$2;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}
And I need to proxy all incoming requests to the shown backend, i.e.
https://devices.example.org/m123
should proxy to http://m123.proxy.tv
https://devices.example.org/m123/favicon.ico
should proxy to http://m123.proxy.tv/favicon.ico
https://devices.example.org/m123/scripts/something.js?params=bar
should proxy to http://m123.proxy.tv/scripts/something.js?params=bar
However, I always get the a Bad Gateway error as a return, and in the logs I get:
[error] 18643#0: *12393 favicon.ico.proxy.tv could not be resolved (3: Host not found)
I assume that my regex somehow malforms the proxy request, but I'm not sure how.
Other combinations that I've tried:
location ~* ^/(.*)(?:/(.*))$
proxied to http://$1.proxy.tv/$2$is_args$args
location ~* ^/(.*)(?:/(.*))?
proxied to http://$1.proxy.tv/$2$is_args$args
Any help is greatly appreciated.