Welcome! Log In Create A New Profile

Advanced

Nginx as reverse proxy - must point to different web servers

Posted by doctau 
Nginx as reverse proxy - must point to different web servers
May 15, 2013 09:35AM
Hello,

i'm a newbie on Nginx and i have this problem :

We have Nginx as reverseproxy who point on a Java server (Platform play) - That's ok and work well :

https://www.toto.fr

Now we would like to point to our Nagios server when we enter this URL https://www.toto.fr/supervision/

For this, i have this block :

location /supervision {
proxy_pass http://IP_SERVER_NAGIOS/nagios/;
proxy_redirect off;
proxy_set_header Host $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-Ssl on;
access_log /var/log/nginx/supervision.access.log;
}

That's work too ! I access well on the start page of Nagios. But when i click on another link of Nagios web interface, Nginx doesn't find the pages because the links point to http://www.toto.fr/nagios/cgi-bin/.... and not to http://www.toto.fr/supervision/cgi-bin/...

What is the way to resolve this problem ? an 'if' condition, a rewrite URL, a new location block ? Can you help me please ?

Thanks

Doctau
Re: Nginx as reverse proxy - must point to different web servers
May 15, 2013 11:59AM
Either create a second location block (location /nagios {...) or update the folder name on the target device to match the existing. It will be difficult to catch absolutely everything with rewrites.
Re: Nginx as reverse proxy - must point to different web servers
May 15, 2013 12:02PM
Hello Doctau,

I'm relatively new to nginx as well, but I think I can propose a solution to your problem. You could use a regular expression (flagged by ~) in your location path to match both /supervision and /nagios:

location ~ ^(/supervision|/nagios) {
---> // your config here
}

I haven't tested this, but I hope my regex fu hasn't failed me. The ^ character says that the match should start at the beginning of the given path expression, so it matches /supervision/bla and /nagios/bla but not /take/me/to/supervision or /hidden/nagios/hack.

For more info on the available options for the _location_ directive, check out the wiki page at http://wiki.nginx.org/HttpCoreModule#location.



Edited 1 time(s). Last edit at 05/15/2013 12:05PM by 0liver.
Re: Nginx as reverse proxy - must point to different web servers
May 15, 2013 12:04PM
Thanks for reply u848237 ! 8)

So, for you there is no simple solution ?

Have you got an idea how can i process ?
Re: Nginx as reverse proxy - must point to different web servers
May 15, 2013 12:11PM
Thanks Oliver for your quick response,

I'll test your solution and will look at the wiki and i'll make a return if its OK !
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 141
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready