# Proxy\_pass to multi background monit http services

**URL:** <https://www.ruby-forum.com/t/proxy-pass-to-multi-background-monit-http-services/161554>\
**Category:** NGINX\
**Created:** [February 27, 2009, 10:37am UTC](https://www.ruby-forum.com/t/proxy-pass-to-multi-background-monit-http-services/161554 "2009-02-27T10:37:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![seven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@seven](https://www.ruby-forum.com/u/seven)\
**Post date:** [February 27, 2009, 10:37am UTC](https://www.ruby-forum.com/t/proxy-pass-to-multi-background-monit-http-services/161554/1 "2009-02-27T10:37:28Z")

</div>

monit has an embedded web interface, I want to use nginx to proxy  
several servers:

[http://monit.example.com/server1](http://monit.example.com/server1)  
[http://monit.example.com/server2](http://monit.example.com/server2)  
[http://monit.example.com/server3](http://monit.example.com/server3)  
[http://monit.example.com/server4](http://monit.example.com/server4)

```
    location /server1/ {
            rewrite ^/sever1/(.*) /$1 break;
            proxy_pass http://localhost:2812; #monit default port
    }
    location /server2/ {.....}

```

The first page of each monit server displays well but because all links  
in monit has absolute path [http://monit.example.com/some\_link](http://monit.example.com/some_link) instead of  
[http://monit.example.com/server1/some\_link](http://monit.example.com/server1/some_link), I don’t know hot to make  
that work.

Can nginx do that? or we need to modify monit?

Thanks

---

<div class="post-metadata">

**Author:** ![seven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@seven](https://www.ruby-forum.com/u/seven)\
**Post date:** [March 23, 2009, 10:39pm UTC](https://www.ruby-forum.com/t/proxy-pass-to-multi-background-monit-http-services/161554/2 "2009-03-23T22:39:13Z")

</div>

Seven Du wrote:

> monit has an embedded web interface, I want to use nginx to proxy  
> several servers:
> 
> [http://monit.example.com/server1](http://monit.example.com/server1)  
> [http://monit.example.com/server2](http://monit.example.com/server2)  
> [http://monit.example.com/server3](http://monit.example.com/server3)  
> [http://monit.example.com/server4](http://monit.example.com/server4)
> 
> ```
> location /server1/ {
> rewrite ^/sever1/(.*) /$1 break;
> proxy_pass http://localhost:2812; #monit default port
> }
> location /server2/ {.....}
> 
> ```
> 
> The first page of each monit server displays well but because all links  
> in monit has absolute path [http://monit.example.com/some\_link](http://monit.example.com/some_link) instead of  
> [http://monit.example.com/server1/some\_link](http://monit.example.com/server1/some_link), I don’t know hot to make  
> that work.

Had the same problem. I was running monit 4.8 and running into the same  
issues. You need monit 4.9 or later to handle reverse proxying. This  
post helped me get monit 4.10 installed without re-compiling from  
source: [http://route19.com/logbook/view/monit-410-on-ubuntu-804](http://route19.com/logbook/view/monit-410-on-ubuntu-804).

> Can nginx do that? or we need to modify monit?

So the answer is yes, nginx can do this with the proper version of  
monit. Here’s the relevant nginx set-up that worked for me:

```
    location /monit/ {
            auth_basic "Restricted";
            auth_basic_user_file /etc/nginx/auth.passwd;
            rewrite ^/monit/(.*) /$1 break;
            proxy_pass http://127.0.0.1:2812/;
    }

```

Hope this helps you

---

<div class="post-metadata">

**Author:** ![seven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@seven](https://www.ruby-forum.com/u/seven)\
**Post date:** [March 24, 2009, 7:07am UTC](https://www.ruby-forum.com/t/proxy-pass-to-multi-background-monit-http-services/161554/3 "2009-03-24T07:07:13Z")

</div>

On Mon, Mar 23, 2009 at 10:39:13PM +0100, Chris Kraybill wrote:

> > ```
> > location /server1/ {
> > 
> > ```
> 
> ```
> location /monit/ {
> auth_basic "Restricted";
> auth_basic_user_file /etc/nginx/auth.passwd;
> rewrite ^/monit/(.*) /$1 break;
> proxy_pass http://127.0.0.1:2812/;
> }
> 
> ```

You do not need rewrite here - proxy\_pass rewrite /monit/\* to /\* by  
itself:

```
     location /monit/ {
              ...

```

- 

```
            rewrite ^/monit/(.*) /$1 break;
            proxy_pass http://127.0.0.1:2812/;

```

---

<div class="post-metadata">

**Author:** ![seven](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3d9bf3/32.png) [@seven](https://www.ruby-forum.com/u/seven)\
**Post date:** [June 25, 2009, 11:52pm UTC](https://www.ruby-forum.com/t/proxy-pass-to-multi-background-monit-http-services/161554/4 "2009-06-25T23:52:28Z")

</div>

my config (nginx replaces location uri with proxy\_pass uri, if you  
specified it after proxy hostname or proxy port) :

```
    location /monit/ {
        allow ;
        deny all;

        sub_filter_once off;
        sub_filter "a href='/" "a href='/monit/";

        proxy_pass http://127.0.0.1:2812/; # pass query to backend 

```

as is  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
}

So, to replace wrong links I’ve used sub\_filter directive. To use it  
nginx must be recompiled with --with-http\_sub\_module (see if you already  
have it - nginx -V).

With all of this configuration only on “\_about” screen is the bug. Do  
you need often see \_about page ? 😉

Proklyatiy yazikivoi barrier…

Posted at Nginx Forum:

> **[Re: proxy\_pass to multi background monit http services](https://forum.nginx.org/read.php?2,306,3395)**
>
> Seven Du wrote: \> monit has an embedded web interface, I want to use nginx to proxy \> several servers: \> \> http://monit.example.com/server1 \> http://monit.example.com/server2 \> http://monit.example.com/server3 \>...
