admin管理员组文章数量:1222507
I am trying to figure out a simple way of writing an nginx proxy_pass condition where depending on the URL called upon (e.g. /go/192.168.0.10) the proxy_pass would take the IP after the /go/ and proxy to HTTP://192.168.0.10:8080/stats.
Basically what I am trying to do is avoid having to write hundreds of individual proxy_pass statements like this
location /go/192.168.0.10 {
proxy_pass http://192.168.0.10:8080/stats;
}
To give context, I have a machine to which I have access, this machine, in turn, can reach multiple remote devices via VPN behind it, and I wish to proxy the web interfaces via the machine I have access to.
Thank you for taking the time to read this and for any assistance you provided.
I am trying to figure out a simple way of writing an nginx proxy_pass condition where depending on the URL called upon (e.g. /go/192.168.0.10) the proxy_pass would take the IP after the /go/ and proxy to HTTP://192.168.0.10:8080/stats.
Basically what I am trying to do is avoid having to write hundreds of individual proxy_pass statements like this
location /go/192.168.0.10 {
proxy_pass http://192.168.0.10:8080/stats;
}
To give context, I have a machine to which I have access, this machine, in turn, can reach multiple remote devices via VPN behind it, and I wish to proxy the web interfaces via the machine I have access to.
Thank you for taking the time to read this and for any assistance you provided.
Share Improve this question edited Feb 6 at 16:14 kasonne asked Feb 6 at 16:09 kasonnekasonne 234 bronze badges1 Answer
Reset to default 0You can use a regex location for this:
location ~ "^/go/(\d{1,3}(?:\.\d{1,3}){3})$" {
proxy_pass http://$1:8080/stats;
}
You can even allow specifying a URI after the device IP:
location ~ "^/go/(\d{1,3}(?:\.\d{1,3}){3})(/.*)?" {
proxy_pass http://$1:8080$2;
}
In case you want to pass a query string too:
location ~ "^/go/(\d{1,3}(?:\.\d{1,3}){3})(/.*)?" {
proxy_pass http://$1:8080$2$is_args$args;
}
本文标签: nginxDynamic Proxy Pass ConfigurationStack Overflow
版权声明:本文标题:nginx - Dynamic Proxy Pass Configuration - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739378671a2160600.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论