Hello,
I found a bunch of thread regarding the migration from nginx and especially try_files
to caddy and tried to use the proposed solutions.
My server handles multiple domains and proxies requests to a node.js app that renders the requested page and saves a static copy of the resulting html to the filesystem. These files should be used for subsequent requests to not put additional load on the node app.
All rendered files are saved with this pattern /var/www/cache/hostname/path/index.html
:
example.com
=> /var/www/cache/example.com/index.html
example.com/some-page/
=> /var/www/cache/example.com/some-page/index.html
example2.com
=> /var/www/cache/example2.com/index.html
first request to example3.com
=> no file exists under /var/www/cache/example3.com/index.html
so forward to node
second request to example3.com
=> /var/www/cache/example3.com/index.html
and so on…
All requests to files e.g. /bundle.js should still be forwarded to the node app.
The caddyfile currently looks like this:
:80 {
root /var/www/cache/
gzip
tls off
log stdout
errors visible
proxy /proxy localhost:3001 {
without /proxy
transparent
}
rewrite / {
to {host}{uri}index.html /proxy{uri}
}
}
no matter what I try to do, I never end up with a prerendered file from the file system. I kind of feel lost here and 90% of time I end up with too many redirects when I try different things.
The desired process is very simple, but I’m not able to figure out a proper config.
Any help would be appreciated.
Thanks in advance.
jsvde