gyptazy

DevOps

Developer

IT Consultant

gyptazy

DevOps

Developer

IT Consultant

Blog Post

Monitorix behind Nginx Reverse Proxy with sub_filter

Monitorix behind Nginx Reverse Proxy with sub_filter

Introducing Monitorix, a versatile, open-source, and lightweight system monitoring tool that excels in overseeing a wide array of services and system resources. Originally crafted for production environments on Linux/UNIX servers, its adaptability extends seamlessly to embedded devices due to its simplicity and compact size.

While Monitorix remains a stalwart choice, contemporary implementations may pose challenges. The conventional practice of exposing services to external entities may not always be ideal, prompting the adoption of a reverse proxy like Nginx as a viable solution. However, managing this setup across multiple systems requires additional configurations.

To streamline this process, leveraging the Nginx subfilter function emerges as an elegant solution. The following snippet illustrates the implementation of this approach.

location /ns01/ {
proxy_pass http://ns01.gyptazy.ch:8080/;
proxy_redirect default;
sub_filter_once off;
sub_filter '/monitorix-cgi/' '/ns01/monitorix-cgi/';
sub_filter '/imgs/' '/ns01/imgs/';
sub_filter '/monitorix/imgs/' '/ns01/imgs/';
sub_filter 'monitorixico.png' '/ns01/monitorix/monitorix/monitorixico.png';
sub_filter 'logo_bot.png' 'monitorix/logo_bot.png';
sub_filter 'logo_top.png' 'monitorix/logo_top.png';
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /ns02/ {
proxy_pass http://ns02.gyptazy.ch:8080/;
proxy_redirect default;
sub_filter_once off;
sub_filter '/monitorix-cgi/' '/ns02/monitorix-cgi/';
sub_filter '/imgs/' '/ns02/imgs/';
sub_filter '/monitorix/imgs/' '/ns02/imgs/';
sub_filter 'monitorixico.png' '/ns02/monitorix/monitorix/monitorixico.png';
sub_filter 'logo_bot.png' 'monitorix/logo_bot.png';
sub_filter 'logo_top.png' 'monitorix/logo_top.png';
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

This solution offers to proxy all Monitorix instances behind a single system which offers SSL/TLS offloading and further authentication mechanism like basic- or mutal authentication. Instances can be chosen by the uri context.

Taggs: