Page 1 of 1

Proxying OTGW web server - absolute URLs

Posted: Sun Mar 01, 2015 12:18 pm
by Stachel
I'm playing a bit with otmonitor (4.2.1) running as a daemon on my Raspberry Pi. I like the web interface a lot, it also appears to be more stable than access OTGW values from within Domoticz (lock ups).

Since I use Nginx already to access Domoticz (because I want HTTPS access, which was not available until recently in native Domotic) I decided to use it as a front-end for the OTGW web server as well.

I proxy the location '/otgw/' to the local port on which OTGW is listening, like so:

Code: Select all

  location /otgw/ {
     proxy_pass http://localhost:8081/;
     proxy_redirect default;
     proxy_set_header        Host            $host:$server_port;
     proxy_set_header        X-Real-IP       $remote_addr;
     proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
  }
This works - sort of: I get the main page with the status overview, but stylesheets, images and links to for example the graph are not working because they are absolute to the webroot. This means that: '/status.html' does not get proxied to '/otgw/status.html' ( which would work), but to '/status.html', which does not exist.

Would it be possible to either replace the absolute URLs with relative URLs, or to replace them with the complete URL (i.e. including host name) so that there's a pattern in the URL that I can rewrite with Nginx directives?


Edit: should have been posted in OTGW subforum - sorry.

Re: Proxying OTGW web server - absolute URLs

Posted: Mon Mar 16, 2015 10:21 pm
by hvxl
I use reverse proxying (with apache) in other situations myself, so I know how useful it can be. I don't know why I didn't think to make that possible by using relative URLs in this case. There seems to be no reason why the URLs should be absolute. I will make that chance in the next version. Thanks for the suggestion.

You know you can run otmonitor in source form and make the changes yourself if you don't want to wait for the next version? See the Opentherm Monitor Sources page for more information.

Re: Proxying OTGW web server - absolute URLs

Posted: Tue Mar 17, 2015 1:58 pm
by adijk
Maybe it's also a goot idea to make a configurable webroot in otmonitor, for those of us using proxypasses?

So to make all html-requests go under, for example, /otgw/status.html where the /otgw-part is configurable?

Re: Proxying OTGW web server - absolute URLs

Posted: Wed Mar 18, 2015 11:50 am
by Ghostbird
I think the easiest way to do this is to download the sources and the tclkit and then run it that way. You can then modify the application to work with a different directory structure.
I did a quick grep on the sources:

Code: Select all

$ grep -n docpath *.tcl
gui.tcl:1302:    global cfg wibblesock theme docpath webstatus
gui.tcl:1305:    foreach dir $docpath {
otmonitor.tcl:18:set docpath {}
otmonitor.tcl:28:lappend docpath [file join $starkit::topdir docroot]
otmonitor.tcl:34:lappend docpath [file join [file dirname $starkit::topdir] html]
web.tcl:374:foreach n $docpath {
It seems to me that the variable docpath constructed in otmonitor.tcl is responsible for pointing the system to the right directories.
However there's no actual html folder as far as I can see, so that may be a runtime Wibble construct, or I may have misunderstood the purpose of otmonitor.tcl:34
You can give it a try, I think the files you'll probably need to modify are web.tcl for the webserver and otmonitor.tcl for the configuration.

Re: Proxying OTGW web server - absolute URLs

Posted: Fri Mar 20, 2015 3:26 pm
by hvxl
adijk wrote:Maybe it's also a goot idea to make a configurable webroot in otmonitor, for those of us using proxypasses?
Once the URL's have been made relative, it's completely unnecessary to make the webroot in otmonitor configurable. With the right proxypass settings it will be possible to access all information presented by the web server, including the websockets.

Re: Proxying OTGW web server - absolute URLs

Posted: Sat Apr 25, 2015 2:05 pm
by bazb
You can also fix this with nginx with the HttpSubsModule. You can then rewrite the paths on the fly.
The easiest way is just to use a subdomain instead of a subfolder.