Stripping the URL suffix lead to a blank screen

1. Caddy version (caddy version):

I’m using the latest docker version, 2.3.0

2. How I run Caddy:

I’m running Caddy 2 inside docker

a. System environment:

  • Ubuntu 18.04.5 LTS x86_64
  • Docker version 19.03.6, build 369ce74a3c
  • docker-compose version 1.26.2, build unknown

b. Command:

for testing:

docker-compose up

to run it

docker-compose up -d

c. Service/unit/compose file:

version: "3.3"
services:
  caddy:
    image: caddy:2.3.0
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./www:/srv
      - ./caddy_data:/data
      - ./caddy_config:/config
    labels:
      - traefik.enable=true
      # HTTPS
      - traefik.http.routers.fenpaws_ssl_caddy.rule=Host(`fenpa.ws`)
      - traefik.http.routers.fenpaws_ssl_caddy.entrypoints=websecure
      - traefik.http.routers.fenpaws_ssl_caddy.tls.certresolver=letsencrypt
      - traefik.http.services.fenpaws_caddy.loadbalancer.server.port=80
      # HTTP
      - traefik.http.routers.fenpaws_caddy.rule=Host(`fenpa.ws`)
      - traefik.http.routers.fenpaws_caddy.entrypoints=web
      - traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https
      - traefik.http.routers.fenpaws_caddy.middlewares=redirect-to-https

d. My complete Caddyfile or JSON config:

:80
root * /srv
file_server browse
uri * strip_suffix .html

3. The problem I’m having:

I’m trying to get rid of the URL suffix like .HTML, .PHP, and so on. I searched quite a bit for a solution and I found that strup_suffix would be the appropriate function for that.

But after I put that directive in my Caddyfile any HTML site I try to access returns nothing but a blank screen.

You can try it here, that’s a simple test HTML.

4. Error messages and/or full log output:

caddy_1  | {"level":"info","ts":1612265583.7895753,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
caddy_1  | {"level":"info","ts":1612265583.7925413,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origin":false,"origins":["[::1]:2019","127.0.0.1:2019","localhost:2019"]}
caddy_1  | {"level":"info","ts":1612265583.7934964,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc0002c0700"}
caddy_1  | {"level":"info","ts":1612265583.7940652,"logger":"http","msg":"server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server","server_name":"srv0","http_port":80}
caddy_1  | {"level":"info","ts":1612265583.796247,"logger":"tls","msg":"cleaned up storage units"}
caddy_1  | {"level":"debug","ts":1612265583.79675,"logger":"http","msg":"starting server loop","address":"[::]:80","http3":false,"tls":false}
caddy_1  | {"level":"info","ts":1612265583.7973864,"msg":"autosaved config","file":"/config/caddy/autosave.json"}
caddy_1  | {"level":"info","ts":1612265583.7974422,"msg":"serving initial configuration"}
caddy_1  | {"level":"debug","ts":1612265589.180427,"logger":"http.handlers.file_server","msg":"sanitized path join","site_root":"/srv","request_path":"/test","result":"/srv/test"}
caddy_1  | {"level":"debug","ts":1612265596.958509,"logger":"http.handlers.rewrite","msg":"rewrote request","request":{"remote_addr":"172.28.0.1:41348","proto":"HTTP/1.1","method":"GET","host":"fenpa.ws","uri":"/test.html","headers":{"Upgrade-Insecure-Requests":["1"],"X-Forwarded-Port":["443"],"Dnt":["1"],"Sec-Gpc":["1"],"User-Agent":["Mozilla/5.0 (X11; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0"],"X-Forwarded-Server":["fenpaws"],"X-Real-Ip":["213.61.250.114"],"Te":["trailers"],"X-Forwarded-Host":["fenpa.ws"],"Accept-Encoding":["gzip, deflate, br"],"Accept-Language":["en,en-US;q=0.7,de;q=0.3"],"X-Forwarded-For":["213.61.250.114"],"X-Forwarded-Proto":["https"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"]}},"method":"GET","uri":"/test"}
caddy_1  | {"level":"debug","ts":1612265596.9587197,"logger":"http.handlers.file_server","msg":"sanitized path join","site_root":"/srv","request_path":"/test","result":"/srv/test"}

5. What I already tried:

I searched this forum and read through the doc doesn’t of times. Mister Google also didn’t help me or I was just too stupid to search for it.

I asked a friend who used Caddy 2 more than me but he also didn’t know the solution for that.

I’m confused, are you using Traefik in front of Caddy?

You could just replace Traefik entirely with Caddy, instead. This plugin will let you configure Caddy using docker labels:

So, you’re actually doing this in the wrong direction – what you want to do is if a request comes in without .html, then you want to see if adding .html to the path will map to a file on disk. Directives like uri strip the prefix after Caddy gets the request, which doesn’t quite make sense.

So right now, if you get a request for /foo.html, then you’re removing the .html and looking on disk for a file called /srv/foo, which won’t exist.

You want to do the opposite, where if you get a request for /foo, you try adding .html to look on disk for /srv/foo.html, and if that exists, rewrite to that path.

This is done with the try_files directive:

try_files {path}.html

This is basically a shortcut for this equivalent config:

@try_files file {path}.html
rewrite @try_files {http.matchers.file.relative}
1 Like

I’m using Traefik in front of Caddy, Caddy is just a webserver for me to serve any site I want. I know that Caddy also has the ability to be used as a reverse proxy, and with Caddy 1 I did that. But that’s now for what I use it for,

Ah okay yeah that makes sense now, as I said I looked for a while on how to do that but I wasn’t able to figure it out. Or I am just bad at googling. I try that directive now.

Thanks for the help

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