Welcome! Log In Create A New Profile

Advanced

Proxying a remote munin server

Posted by alexolivan 
Proxying a remote munin server
December 29, 2014 04:24AM
Hi NGINX comunity!

Has anyone ever tried (or succeeded!) on proxying a remote munin server?

What I'm trying to do is to create a location on my nginx server vhost (let's say "/graphs").
Then, under /graphs, I want to let nginx to proxy the graphs structure from a remote munin (CGI driven) server (let's say http://my-munin-server/munin) ...
Obviously, this still sound no tricky (even me, I have succedded on doing this) unless the las thing I really want:
I do not want the whole /munin graphs structure to be proxied under /graphs , but I only want a portion (for privacy reasons) of the munin graphs structure to appear under /graphs (let's say I want to proxy just http://my-munin-server/munin/my-domain.com).

I have even succeded on doing this, but the results are partial, and from this endpoint I habe been several days googling with no success:
The problem is that I got the site proxied with no css, no static contents, no images ... so it all is useless
By reading the code I see plenty of ../ ../.. ../../../ on the original munin server code, so I guess I have a relative path problem, but I have not succeeded on solving it using rewriting / proxy_pass stuff.
munin server itself is nginx driven, and uses the widely / googlely available "munin over nginx setup"

Nobody at the munin comunity seems to have ever tried or succeeded on this, so they expect someone to be the first and let it be documented... but it is beyond my knowledge

So... I thought we may got a chance hitting directly on the hornet's nest (NGINX comuninty!)

Anyhow, thank you very much for your curiosity!
Best regards!
Re: Proxying a remote munin server
January 02, 2015 07:14AM
I think I' m getting reaaaally close...

It turned out to be far more complex that I thought...
To succeed I use a combination of rewrites, in a determined sequence, playing with last and break at the end, to control what goes to the remote munin server. this is DONE

The problem comes with the reply from the munin server... I need to modify it
I had to recompile in order to use the subs filter, so it is not an "out of the box" (or at least I did not figure out how to do it anotherway)
Once with subs filter enabled, I can deal with modifying the munin server reply...

Her comes the nex question.... how to replace "../" appearances with nothing?
I need to delete ../ ../../ strings on the reply, but I'm not succeeding...

Here I post what I have done so far.... (maybe also helps somebody :-) )

location /graphs/ {
subs_filter_types text/html text/css text/xml;
subs_filter href=" href="http://somedomain.example.com/graphs/;
subs_filter (../*) ir;

proxy_buffering off;

rewrite /graphs/munin/static/(.*) /munin/static/$1 break;
rewrite /graphs/munin/(.*) /munin/somedomain.example.com/Servers/somedomain/$1 break;
rewrite /graphs/munin-cgi/(.*) /munin-cgi/munin-cgi-graph/somedomain.example.com/Servers/somedomain/$1 break;


rewrite /graphs/(.*).(png|jpg|gif) /graphs/munin-cgi/$1.$2 last;
rewrite /graphs/(.*)/(static)/(.*) /graphs/munin/static/$2 last;
rewrite /graphs/(.*) /graphs/munin/$1 last;


proxy_pass http://my-munin-server.example.com/;

proxy_redirect default;
}

note the line: subs_filter (../*) ir; ... this is where I'm stuck...
I need something like: subs_filter (../*) NULL ir; in order to delete ../ appearances

Best regards to everyone and happy new year!!!
Re: Proxying a remote munin server
January 02, 2015 08:32AM
INITIALLY SOLVED...

There is room for refinement... but that works quiet well!

location /graphs/ {
subs_filter_types text/html text/css text/xml;
subs_filter href="(../)* href="http://somedomain.example.com/graphs/ ir;
subs_filter src="/munin-cgi/munin-cgi-graph/somedomain.example.com/Servers/somedomain/ src="http://somedomain.example.com/graphs/;

proxy_buffering off;

rewrite /graphs/munin/static/(.*) /munin/static/$1 break;
rewrite /graphs/munin/(.*) /munin/somedomain.example.com/Servers/somedomain/$1 break;
rewrite /graphs/munin-cgi/(.*) /munin-cgi/munin-cgi-graph/somedomain.example.com/Servers/somedomain/$1 break;


rewrite /graphs/(.*).(png|jpg|gif) /graphs/munin-cgi/$1.$2 last;
rewrite /graphs/(.*)/(static)/(.*) /graphs/munin/static/$2 last;
rewrite /graphs/(.*) /graphs/munin/$1 last;


proxy_pass http://my-munin-server.example.com/;

proxy_redirect default;
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 101
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready