Lately, I have been interested in monitoring my VMs and looking at pretty graphs with statistics on how a machine is performing. I came across a pretty sweet tool called net-data, which provides real-time data on performance and health monitoring. The only problem I have with net-data is that the web portion of net-data is served on port 19999, which is an ugly number and being the nit-pick that I am seeing it in the address bar is pain.
To remedy this, I decided to find a way to ‘serve’ the net-data web ui to a sub-domain instead.
So this is how I originally envisioned the set-up would work:
- Set-up a sub-domain such as web.kelvinsblog.com
- When I visit the above sub-domain, it will serve the net-data web ui that is located at kelvinsblog.com:19999
- I did not want this to be a re-direct, I want to preserve the web.kelvinsblog.com domain in my address bar.
The best solution I found for this was to use Apache and define a VirtualHost for my sub-domain. Essentially, the set-up is to leverage mod_proxy in Apache and set-up a reverse proxy so that web.kelvinsblog.com, will serve the web ui located at port 19999
How was this done
First, I created a conf file in /etc/httpd/conf.d for my sub-domain:
$ vim /etc/httpd/conf.d/web.kelvinsblog.com
I believe the ‘CentOS’ standard is to place any additional conf files in conf.d whereas Debian/Ubuntu, virtualhosts can be added straight to the main conf file. I could be wrong though.
In the conf file, the following settings will result in the sub-domain serving the web page on a desired port. I am using a reverse proxy to achieve this:
Require user kelvin
Allow from all
ProxyPass / http://localhost:19999/
ProxyPassReverse / http://localhost:19999/
- ProxyPreserveHost keeps the sub-domain the address bar. This is to prevent having the actual address from being exposed (aka http://localhost:19999/)
- ProxyRequests Off – If this is set to ‘On’, your Apache server basically operates as a open proxy server, which is dangerous. The setting should only be ‘On’ if you have confidently secured your server. As well from the Apache website:
ProxyRequestsdirective should usually be set off when using
After adding the configuration and restarting Apache, visiting the sub-domain should now serve the web page hosted at the specified port.
Usually I like to add a ‘lessons learned’ section to kind of go over what I learned from the process. What have I learned from this exercise?
READ THE DOCS!
Why? Cause the creator added a handy wiki page that goes over everything I tried to do on my own.. Basically, what took a few hours could have taken a just a hour (or less).
The good thing is that I learned quite a bit about Apache.