What's the recommended way to set up Grafana behind Caddy?

Hello y’all!

I’m working on setting up Grafana that will be behind Caddy. I want to setup something similar to Nginx’s proxy pass. For example, here is the Nginx config I have:

location / {
  	proxy_pass http://localhost:3000;
	proxy_http_version 1.1;
	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header Connection 'upgrade';
	proxy_set_header Host $host;
	proxy_cache_bypass $http_upgrade;
}

I created the following Caddyfile to do the same for me:

example.com {
        tls example@example.com
        gzip
        proxy / localhost:3000 {
                transparent
        }
}

What would you add or change in the current file, taking production use in the account? I seem to accomplish the same effect as with Nginx, but I would like to gather more opinions from the community.

Thank you very much.

You might also want to add the websocket preset. That’ll proxy the Upgrade and Connection headers through.

1 Like

Such as in the following example?

example.com {
        tls example@example.com
        gzip
        proxy / localhost:3000 {
                transparent
                websocket
        }
}
2 Likes

Yup​​

Thank you very much Matt, this works flawless!

Hi, previous posts was not working for me, here is what’s working:

caddyFile

  proxy /metrics http://localhost:3000/ {
         without /metrics
         transparent
         websocket
  }

defaults.ini from Grafana

[server]
domain = mydomain.com
root_url = %(protocol)s://%(domain)s:/metrics

Cheers!

2 Likes