Papermerge & Caddy, serving seemingly empty css files

1. Caddy version (caddy version): v2.2.1

2. How I run Caddy:

a. System environment:

Ubuntu 20.04, as systemd service (installed with default config from packages)

d. My complete Caddyfile or JSON config:

chlin15-4.ch.dom:80 {
  reverse_proxy / 127.0.0.1:9001
  file_server /static {
    root /opt/PapermergeDMS/static
    browse
  }
  file_server /media {
    root /opt/PapermergeDMS/media
    browse
  }
  header /static/admin/css/* {
    Content-Type "text/css; charset=utf-8"
  }
  log {
    level warn
  }
  encode zstd gzip
}

3. The problem I’m having:

CSS isn’t being applied. Looking at the browser console, it seems like all css files are being found (no 404, no other error), however they’re empty. This - of course - is not the case on the server.

4. Error messages and/or full log output:

Browser only reports an “Uncaught ReferenceError: $ is not defined”, which I don’t suspect to stand in relation with this issue.

fetched css files are seemingly empty:
image

5. What I already tried:

Changed matchers, trying out different formats (/static, /static/, /static/*).
Didn’t help, only resulted in 404 errors.

6. Links to relevant resources:

NGINX-Tutorial for Papermerge:


There are no guides for using caddy, but I wanted to try anyways (obviously).

Path matchers are exact-match, so you need the * suffix for it to match any path below it.

Also, the file server appends the request path to the root when looking for files on disk, so with your current config, it would be looking at /opt/PapermergeDMS/media/media for example.

I think this is what you want, instead:

chlin15-4.ch.dom:80 {
	root * /opt/PapermergeDMS

	encode zstd gzip
	header /static/admin/css/* {
		Content-Type "text/css; charset=utf-8"
	}

	@notStatic path /media* /static*
	reverse_proxy @notStatic 127.0.0.1:9001

	file_server browse

	log {
		level warn
	}
}

So basically, any request that isn’t to either /media* or /static* will go through the reverse_proxy, and anything else (i.e. /media* and /static*) will be handled by the file server.

2 Likes

You actually forgot the “not” in front of “path” ^^

However, after adding that, it work’s like a charm. I don’t even need to set headers manually now.
Thank you so much!

This is the config I’m now using:

chlin15-4.ch.dom:80 {
  root * /opt/PapermergeDMS
  @notStatic not path /media* /static*
  reverse_proxy @notStatic 127.0.0.1:9001
  file_server
  encode zstd gzip
  log {
    level warn
  }
}
3 Likes

Whoops my bad! Good catch :smile:

Glad it worked for you!