Rewrite nginx "rewrite block" to caddy

andrei@globus:/var/www$ caddy -version
Caddy 0.10.12 (non-commercial use only)
andrei@globus:/var/www$ caddy -log stdout
Activating privacy features... done.
http://:2015
2018/04/03 13:00:02 http://:2015
127.0.0.1 - - [03/Apr/2018:13:01:15 +0800] "HEAD /assets/theme/main/js/bootstrap-switch.js HTTP/1.1" 200 0 "-" "curl/7.55.1" /// /assets/theme/main/js/bootstrap-switch.js

It works well:

curl -I http://localhost:2015/assets/theme/main/js/bootstrap-switch.js
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 14919
Content-Type: application/javascript
Etag: "p59kitbif"
Last-Modified: Thu, 08 Mar 2018 08:49:41 GMT
Server: Caddy
Date: Tue, 03 Apr 2018 05:01:15 GMT

Alright! Now we’ve got a known working configuration, it’s time to slowly - one-by-one - add the other directives and snippets back in to your Caddyfile.

If/when it breaks again, you should be able to pin-point what the problematic configuration is.

The problem is “cache” directive, after i turn it on everything stops working.

Could be a bug of some kind in recent versions… The cache plugin is developed by @nicolasazrak:

If you could narrow your Caddyfile down to the simplest possible version that breaks with cache present (does it happen just with cache and any rewrite?) and post an issue to that Github repository (possibly linking to this forum thread), he should be better able than I to help sort it out.

1 Like

Just add cache directive to your example and it already doesn’t work

:2015 {
  root /var/www/html/my-host.com
  log / stdout "{combined} /// {rewrite_uri}"
  errors stdout
  rewrite {
    to {path} {path}/ /index.php?q={uri}
  }
  cache
}

Unfortunatelly this plugin seems to be abandonned, there is another person in issues who reported that cache breaks redir behavior, i believe it’s the same problem… But no reaction from author and last commin in Aug 2017

That’s unfortunate news.

Your best bet might be to look into Varnish or similar software to handle caching for you instead.

Author of cache module here. Sorry if it seems abandoned. I’m not adding new features but I’m looking if an issue appears. I’ll try to investigate both of the opened issues.

2 Likes

Alright, thanks, i’m happy to hear it, if you need any help or additional information, just ask.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.