Today I wanted to setup monit behind Apache proxy on my webserver, which runs ISPConfig (https://www.ispconfig.org/) under Debian. Monit is a OpenSource monitoring tool for Linux (see https://mmonit.com/monit/).
Requirements
I had the following requirements on the solution:
- monit should only be accessible from the server itself (localhost)
- monit should run under a special SSL-secured URL (not IP:PORT as in default)
- monit should run password protected
set httpd port 2812 and use address 127.0.0.1 # bind to loopback only allow localhost # allow only localhost to connect to the server and allow ask:sheldon # require user 'ask' and password 'sheldon'
Software Versions
- Debian 3.16.39-1 (2016-12-30) x86_64 GNU/Linux
- ISPConfig 1.3.2
- Apache 2.4.10 (Debian)
- Monit version 5.20.0
Steps to setup monit behind Apache proxy
- First I had to login as root. But sudo-ing with a sudoers user should work as well.
- Install monit:
$> apt-get install monit $> service monit start
- Add a new config file under /etc/monit/conf.d/ask-sheldon.cfg with the following content:
set httpd port 2812 and use address 127.0.0.1 # bind to loopback only allow localhost # allow only localhost to connect to the server and allow ask:sheldon # require user 'ask' and password 'sheldon'
- Setup a subdomain monitoring.ask-sheldon.com as a new website (sites tab in ISPConfig) with Let’s Encrypt (https://letsencrypt.org/) as SSL-maintainer and such stuff.
- Enabled http-proxy module for Apache:
$> a2enmod proxy_http $> service apache2 restart
- Add the proxy definition to the Apache directives in ISPConfig:
ProxyPass /monit/ http://127.0.0.1:2812/ ProxyPassReverse /monit/ http://127.0.0.1:2812/ <Location /monit/> Order deny,allow Allow from all ProxyPassReverseCookiePath / /monit/ </Location>
The Apache directives can be found in the site administration of the respective website in the options tab as shown below.
That’s it! That’s how I setup monit behind Apache proxy. Now I was able to call monit via the following URL in webbrowser:
https://monitoring.ask-sheldon.com/monit/
Finally I put this URL together with the given credentials to the server configuration of ISPConfig (System Tab -> Server Config):
Afterwards the monit monitoring can be seen in ISPConfig backend (Monitor Tab -> Show Monit)