Tuesday, January 17, 2017

OpenHAB nginx proxy based on user agent

This post will cover using an nginx server to conditionally proxy_pass to OpenHAB based on if the URL is being requested from the OpenHAB iOS App determined by the user agent of the request.
My setup has 3 machines of relevance:
  • Machine A hosts software known as BlueIris. This software records network enabled camera streams to disk, provides interfaces to review this footage, and can push alerts to iOS apps. This machine is not routable to the internet
  • Machine B is a Raspberry Pi 3 running OpenHAB 1.X. This machine is also not routable to the internet. 
  • Machine C is a Raspberry Pi 3 with nginx acting as a proxy. It has an SSL certificate from LetsEncrypt. It is routable to the internet, having dual homes. 
The desire is to route all traffic to Machine A, unless the request is coming from an application with the user agent containing "OpenHAB". This will be accomplished using "evil ifs". This method works for me, but your mileage may vary.