1. The problem I’m having:
I have locally saved mine old web-site. This site was built with SSI, CGI (Perl scripts) technologies. I already successfully adapt it for running with lighttpd. Now I want to adapt this site for running with Caddy2.
So, for replacing original SSI technology I need to use Caddy’s templates with include. Goal is to include one HTML file into another.
Example of my site’s file structure:
web-site’s root/index.shtml
web-site’s root/left.html
“index.shtml” includes “left.html” by this string:
<!--#include virtual="left.html"-->
But for now, I am using these test files with default delimiters “{{” “}}”:
web-site’s root/index.html
web-site’s root/index.shtml
web-site’s root/include.htm
Now my tryouts with defaults:
- If index file is index.html
curl -v http://example.com/
- include works - If directly get “index.html”
curl -v http://example.com/index.html
- include works - If use as index file “index.shtml”
curl -v http://example.com/index.shtml
- include do not work nor with indirect access, nor with direct access
My bet that problem is somehow connected with MIME. Docs:
…any responses that do not have a qualifying Content-Type will not be evaluated as templates
But, as testing “index.shtml” I am using simply renamed same “index.html”:
<html>
<body>
{{include "./include.htm"}}
<br>
{{.RemoteIP}}
</body>
</html>
Now I am absolutely do not know what to do else. Thanks for any help!
2. Error messages and/or full log output:
...
2023/12/14 10:17:28.489 DEBUG http.auto_https adjusted config {"tls": {"automation":{"policies":[{}]}}, "http": {"servers":{"srv0":{"listen":[":80"],"routes":[{"handle":[{"handler":"subroute","routes":[{"handle":[{"handler":"vars","root":"/srv"},{"encodings":{"gzip":{}},"handler":"encode","prefer":["gzip"]},{"delimiters":["{{","}}"],"handler":"templates","mime_types":["text/html","text/plain","text/markdown"]}]},{"handle":[{"executable":"/usr/local/bin/test.sh","handler":"cgi"}],"match":[{"path":["/test"]}]},{"handle":[{"browse":{},"handler":"file_server","hide":[".git","/etc/caddy/Caddyfile"],"index_names":["index.shtml"]}]}]}],"terminal":true}],"automatic_https":{"disable":true}}}}}
...
2023/12/14 10:17:49.762 DEBUG http.handlers.file_server sanitized path join {"site_root": "/srv", "request_path": "/", "result": "/srv"}
2023/12/14 10:17:49.762 DEBUG http.handlers.file_server located index file {"filename": "/srv/index.shtml"}
2023/12/14 10:17:49.762 DEBUG http.handlers.file_server opening file {"filename": "/srv/index.shtml"}
curl output:
clear && curl -vL http://my.example.com/index.shtml
* Trying MY_IP:80...
* Connected to my.example.com (MY_IP) port 80 (#0)
> GET /index.shtml HTTP/1.1
> Host: my.example.com
> User-Agent: curl/7.81.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Content-Length: 77
< Etag: "s5nk8s25"
< Last-Modified: Thu, 14 Dec 2023 10:38:52 GMT
< Server: Caddy
< Date: Thu, 14 Dec 2023 10:40:19 GMT
<
<html>
<body>
{{include "./include.htm"}}
<br>
{{.RemoteIP}}
</body>
</html>
* Connection #0 to host my.example.com left intact
3. Caddy version:
docker exec affectionate_lamport caddy version
:
v2.7.6 h1:w0NymbG2m9PcvKWsrXO6EEkY9Ru4FJK8uQbYcev1p3A=
4. How I installed and ran Caddy:
a. System environment:
Ubuntu Server 22, x86_64, Docker.
b. Command:
build.sh:
docker build --rm --tag "mycaddy:latest" ./
docker run --rm --tty --publish 80:80 --publish 443:443 mycaddy:latest
Run:
nano Caddyfile && ./build.sh
c. Service/unit/compose file:
Dockerfile:
FROM caddy:builder AS builder
RUN xcaddy build \
--with github.com/aksdb/caddy-cgi/v2
FROM caddy:latest
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
COPY ./Caddyfile /etc/caddy/Caddyfile
COPY ./site /srv
COPY ./site/cgi-bin/test.sh /usr/local/bin/
EXPOSE 80
EXPOSE 443
VOLUME /data
VOLUME /config
d. My complete Caddy config:
Caddyfile:
{
debug
order cgi before respond
}
http://my.example.com {
file_server {
index index.shtml
hide .git
browse
}
root * /srv
cgi /test /usr/local/bin/test.sh
templates * {
mime "text/html" "text/plain" "text/markdown"
between "{{" "}}"
# "<!--#" "-->"
}
encode gzip
# @shtml path *.shtml
# header @shtml Content-Type text/html
}