Hi, I am just looking for help with structuring my Caddyfile. I can’t figure out how to do rewrites internally so they don’t change the end user url. Alternatively, I would like to allow browsing of a directory ourside the root folder.
I have the following directory structure:
www
\ downloads
- v1.1.zip
- v1.2.zip
- etc
\ blog
- 201612-december-update.md
- 201611-november-update.md
\ release
- index.md
- blog.md
- about.md
\ templates
- default.html
- blog.html
\ css
- main.css
- app.css
\ js
- main.js
- app.js
The reasoning behind the above directory structure is that the release
folder contains all the application-y stuff and the content is outside. The application gets updated regularly whereas the
content will occasionally change.
I would like the following outcome:
myurl.com -> index.md (using default.html template)
myurl.com\about -> about.md (using default.html template)
myurl.com\downloads -> browse www\downloads directory
myurl.com\app -> proxy to a nodejs app
myurl.com\{css,js} -> serve the js and css in release folder
myurl.com\blog -> blog.md (using default.html template)
myurl.com\blog\201612-december-update
-> 201612-december-update.md (using blog.html template)
As mentioned above I have tried two different approaches, but I am nowhere close
to the above outcome.
1) setting release as the root of the site and rewriting to other urls
*:80 {
root /var/www/release
gzip
tls off
ext .md
rewrite /downloads {
to /../downloads{uri}
}
browse /downloads
rewrite /blog {
to /../blog/{uri}
}
proxy /app localhost:3000
markdown {
template templates/default.html
template blog templates/blog.html
}
}
2) setting www as the root of the site and rewriting the other urls
*:80 {
root /var/www
gzip
tls off
ext .md
browse /downloads
rewrite / /release
rewrite /about /release/about
rewrite /blog /release/blog
rewrite /css /release/css
rewrite /js /release/js
proxy /app localhost:3000
markdown {
template release/templates/default.html
template blog release/templates/blog.html
}
}
My issues are as follows:
In approach number 1, I cannot browse the downloads and the blog posts do not work. The main /blog page works but none of the posts at /blog/201612-december-update will show up.
In approach number 2, urls do not look as intended; for example the homepage url becomes myurl.com/release (similar to a redirect; I thought rewrite just performed an internal rewrite). The same thing happens to the about and main blog page. Additionally, in exact opposite of approach 1, the main blog does not work but the individual posts work.
I suspect this may be fixed, if I move the static assets inside the release folder, but that is a limitation of the deployment method I am using (anistrano.deploy for ansible).
Can someone please point out if this is possible and if I am doing something totally out of whack? I have tried various mix and matches of the above and still no luck.