Grafana not working after upgrade to v2

1. Caddy version (caddy version):

v2.0.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8=

2. How I run Caddy:

I have a pfsense router that sends 80 and 443 to caddy on my newly installed ubuntu 20.04 server.

a. System environment:

ubuntu 20.04, systemd

b. Command:

I use systemd

ExecStart=/usr/bin/caddy run --environ --config /media/data/1/Caddyfile

c. Service/unit/compose file:

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target

[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /media/data/1/Caddyfile
ExecReload=/usr/bin/caddy reload --config /media/data/1/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddyfile or JSON config:

(mycommon) {
  try_files {path}.html {path}.htm {path}.php {path}
  root * /var/www           # Change path & syntax for your OS or your preferred location!
  encode gzip
 
  header / {
    X-Content-Type-Options nosniff
    X-XSS-Protection "1; mode=block"
    Strict-Transport-Security "max-age=31536000;"
  }

(mylocations) {

  reverse_proxy /grafana* 127.0.0.1:3000 {        
  }
}

****.net {
  tls ****@gmail.com          # Email for Let's Encrypt Verification

  log {
    output file /media/data/1/caddy/access.log {                          # Change path syntax for your OS or your preferred location!
      roll_size      10MiB          # Rotate after 1 MB
      roll_keep      5          # Keep at most 2 log files
    }
  }
  log {
    output file /media/data/1/caddy/errors.log {                          # Change path syntax for your OS or your preferred location!
      roll_size      10MiB          # Rotate after 1 MB
      roll_keep      5          # Keep at most 2 log files
    }
    level ERROR
  }

  import mycommon	 	   # Import code snippet 1 defined above
  import mylocations  	   # Import code snippet 2 defined above
}


http://localhost http://10.0.2.40 {

  import mycommon	 	   # Import code snippet 1 defined above
  import mylocations  	   # Import code snippet 2 defined above

}

3. The problem I’m having:

when using grafana in docker, I’m getting the error “*****.net redirected you too many times” in chrome. This set up previously worked in caddy using

proxy /grafana 127.0.0.1:3000 {             
      without /grafana	
      transparent	
  }

4. Error messages and/or full log output:

Not sure how to troubleshoot

5. What I already tried:

tried following the migration guide (other resources on the server work fine, this is the last one!), but unable to figure out the problem

6. Links to relevant resources:

Howdy @dpeet, welcome to the Caddy community!

The without subdirective for proxy in v1 was a bit of a way to ‘hack in’ rewriting functionality directly into the proxy itself, to handle that specific case where you need to strip a prefix before proxying.

It’s not needed in v2 because you can manipulate the URI however and whenever you like.

I’d recommend that as an equivalent to your v1 config:

The following would likely work best:

route /grafana* {
  uri strip_prefix /grafana
  reverse_proxy 127.0.0.1:3000
}

As you can see the URI rewriting functionality is not a part of the proxy any more but can easily be done before proxying regardless.

route (Caddyfile directive) — Caddy Documentation
uri (Caddyfile directive) — Caddy Documentation

Awesome, that was simple enough. Worked for me, thanks again for the help and the great software!

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.