From b9f9eefd3099d531e20939c3c72cc3528d2fefb3 Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Wed, 20 Aug 2014 09:27:10 +0200 Subject: [PATCH] Added the new 'url_prefix_proxy' option to bypass the URL building in the CGI. Closes #58 --- Changes | 4 +++- man/man5/monitorix.conf.5 | 9 +++++++++ monitorix.cgi | 13 ++++++++----- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Changes b/Changes index fd2f4ce..62f7d11 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,4 @@ -3.N.N - DD-MMM-2014 +3.N.N - DD-Aug-2014 ==================== - Added a complete statistical Libvirt (libvirt) graph. - Added a complete processes statistics (process) graph. @@ -17,6 +17,8 @@ (suggested by Russell Morris, rmorris AT rkmorris.us) - Added SPF statistics in the 'mail' graph. - Added support for newest NVidia driver 340.24. [#54] +- Added the new 'url_prefix_proxy' option to bypass the URL building in the CGI. + Usefull when Monitorix is used behind a reverse proxy. [#58] - Improved in all graphs the 'limit' and 'rigid' functionality and reduced a lot of redundant code. - Changed all DST from COUNTER to GAUGE in 'net' module to avoid unexpected huge diff --git a/man/man5/monitorix.conf.5 b/man/man5/monitorix.conf.5 index 143d7d5..88da207 100644 --- a/man/man5/monitorix.conf.5 +++ b/man/man5/monitorix.conf.5 @@ -156,6 +156,15 @@ Although this is a global option, only the graphs \fIport\fP, \fInginx\fP and \f Default value: \fIfilter\fP .RE .P +.BI url_prefix_proxy +.RS +This option forces \fImonitorix.cgi\fP to bypass the URL building. This is specially usefull when Monitorix is used behind a reverse proxy. +.P +An example would be: \fIhttp://myexternalwebsite.com/\fP +.P +Default value: +.RE +.P .BI base_dir .RS This is the absolute path to the directory where all the web elements are located: diff --git a/monitorix.cgi b/monitorix.cgi index ea43c40..c2800c7 100755 --- a/monitorix.cgi +++ b/monitorix.cgi @@ -257,11 +257,14 @@ if($config{include_dir} && opendir(DIR, $config{include_dir})) { } } -$config{url} = ($ENV{HTTPS} || ($config{httpd_builtin}->{https_url} || "n") eq "y") ? "https://" . $ENV{HTTP_HOST} : "http://" . $ENV{HTTP_HOST}; -$config{hostname} = $config{hostname} || $ENV{SERVER_NAME}; -if(!($config{hostname})) { # called from the command line - $config{hostname} = "127.0.0.1"; - $config{url} = "http://127.0.0.1"; +$config{url} = ($config{url_prefix_proxy} || ""); +if(!$config{url}) { + $config{url} = ($ENV{HTTPS} || ($config{httpd_builtin}->{https_url} || "n") eq "y") ? "https://" . $ENV{HTTP_HOST} : "http://" . $ENV{HTTP_HOST}; + $config{hostname} = $config{hostname} || $ENV{SERVER_NAME}; + if(!($config{hostname})) { # called from the command line + $config{hostname} = "127.0.0.1"; + $config{url} = "http://127.0.0.1"; + } } $config{url} .= $config{base_url};