I am trying to serve an HTML/CSS/JS static website from Caddy.
I want it to be accessible at 192.168.1.210/website and I am trying with:
192.168.1.210/website {
root /srv/mywebsite
}
This serves index.html but not the *.js and *.css files which are in the javascript and css directories along index.html. I have read the doc, the examples and tried many rewrites but none works for me so far.
For now I am running an Nginx server to serve the website and Caddy simply proxies to it, which is rather clumsy.
Unless the javascript and css folders are in a folder called website, those paths will not work. They have to be relative to the website folder (which may not exist, but that caddy config makes it look real to the client).
For now the file structure is:
/srv/
β mywebsite/
β β index.html
β β javascript/
β β β startup.js
β β css/
β β β style.css
The index.html loads but the browser tries to load 192.168.1.210/javascript/startup.js instead of 192.168.1.210/mywebsite/javascript/startup.js. Is it not possible to rewrite the requests somehow with Caddy ?
The only way to intercept these with Caddy is to write another site label that catches non-/website-prefixed URIs, like:
192.168.1.210 {
redir 301 {
if_op or
if {path} starts_with /css
if {path} starts_with /js
/ {host}/website{uri}
}
}
But I would probably look at the browser as the culprit for now - the format you used in the HTML example above is relative, and a modern browser should be prepending /website if thatβs whatβs already in the URL bar.