Installing and configuring reverse proxy for Grafana
This guide describes how to install and configure the Caddy webserver as proxy for Grafana.
Caddy: webserver
Download and install Caddy
Install packages needed for Caddy.
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-httpsAdd the Caddy repositories and its signing key to the server.
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg && curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.listInstall the Caddy webserver which routes traffic of the services on the server.
sudo apt update && sudo apt install -y caddyReload the system daemon, start Caddy and show the Caddy status to check if it's set to active.
sudo systemctl daemon-reload && sudo systemctl start caddy && sudo systemctl status caddyConfigure Caddy
Open the Caddy configuration file and press i to be able to edit (insert) the file.
sudo vi /etc/caddy/CaddyfileReplace its full content with the following:
:443 {
tls {
alpn http1.1 h2
}
reverse_proxy http://localhost:3000
}Press ESC to quit editing the file, and type :wq to save (write) and quit the file.
Validate the Caddy configuration to check if there is no ERROR listed. If an error occurred, see the troubleshooting section.
sudo caddy validate --config /etc/caddy/CaddyfileStop and start caddy for the changes to take effect (intentionally no restart is used).
sudo systemctl stop caddy && sudo systemctl start caddyAt this point Caddy listens on :443 but has no certificate yet, so HTTPS does not work. Next, install a TLS certificate to serve Grafana and Factry Historian over HTTPS.
Troubleshooting
Caddy failing to start
- Make sure validation does not return any errors:
sudo caddy validate --config /etc/caddy/Caddyfile- Resolve the errors if there are some and stop and start Caddy again.
sudo systemctl stop caddy && sudo systemctl start caddy