Help with monit config


(Kieran Wynne) #1

I’m trying to proxy monit

I’ve got the base domain working fine. for example domain.com/monit

proxy /monit :8081 {
    without /monit
}

However all the links on the page lead to the root domain… So a link on the page would read https://domain.com/sublink
I’ve tried a lot of different regex rules, but in all honesty I don’t know what I’m doing with it. I found an nginx config which I tried converting

from nginx

location /monit {
        rewrite ^/monit/(.*) /$1 break;
        proxy_pass        http://localhost:2812/;
        include proxy.inc;
}

to caddy

rewrite /monit {
    r ^/monit/(.*)
    to /{1}
}
proxy /monit :8081 {
    without /monit
}

Has anyone had any luck with this? Or any tips?

UPDATE:
just found the following nginx config from the official site

    location /monit/ {
        rewrite ^/monit/(.*) /$1 break;
        proxy_ignore_client_abort on;
        proxy_pass   http://192.168.1.10:2812; 
        proxy_redirect  http://192.168.1.10:2812 /monit; 
        proxy_cookie_path / /monit/;
    }

(Matthew Fay) #2

Hi @k33k00,

The nginx proxy_redirect function rewrites Location headers coming back from upstream to conform to the location accessed by the client.

Caddy can’t easily manipulate the Location header in this way yet, but there’s an outstanding pull request with this functionality: https://github.com/mholt/caddy/pull/2144

Once it’s merged, you can make use of that - and http.filter for links in HTML - to reverse proxy an app into a folder without the app having to support that configuration.

In the mean time, you’ll need to configure any app to use the correct base path, or give it a subdomain rather than a subfolder.


(Kieran Wynne) #3

Thanks for the reply, just knowing it can’t be done yet will save me some sanity. I’m trying to avoid subdomains as much as possible.

I have found a work around that seems to be working. It feels a little hacky but it works for monit which has no config options for the base path.

test.com {
    redir 301 {
        if {>referer} is https://test.com/monit
        if {path} not_has monit/
        / /monit/{path}
    }
    proxy /monit :8081 {
        without /monit
    }
}

(Matthew Fay) #4

Wow, checking {>referer} seems pretty smart! Can’t believe I never thought of that before. Thanks for sharing your workaround.