{{ Templates }} are not working for me

1. Caddy version (caddy version):

v2.4.7-0.20220219223636-186fdba916a1

2. How I run Caddy:

sudo ./caddy reverse-proxy --to 127.0.0.1:8080

a. System environment:

Solus OS (latest)

d. My complete Caddyfile or JSON config:

templates

3. The problem I’m having:

I have the following files:
wow.html:

<html>
  <body>
    <h1>Test!</h1>
    {{include "./test.html"}}
  </body>
</html>

test.html:

<p>Wow this is really cool!</p>

Now I do:
curl -k https://localhost:443/wow.html
Which returns:

<html>
  <body>
    <h1>Test!</h1>
    {{include "./test.html"}}
  </body>
</html>

This is what I get when starting Caddy, I do get a certificate error on launch, but I’m assuming that the templating is unrelated to the connection:

2022/03/02 04:42:12.784	WARN	admin	admin endpoint disabled
2022/03/02 04:42:12.785	INFO	http	server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS	{"server_name": "proxy", "https_port": 443}
2022/03/02 04:42:12.785	INFO	http	enabling automatic HTTP->HTTPS redirects	{"server_name": "proxy"}
2022/03/02 04:42:12.785	INFO	tls.cache.maintenance	started background certificate maintenance	{"cache": "0xc0003c8000"}
2022/03/02 04:42:12.786	INFO	http	enabling automatic TLS certificate management	{"domains": ["localhost"]}
2022/03/02 04:42:12.786	WARN	tls	stapling OCSP	{"error": "no OCSP stapling for [localhost]: no OCSP server specified in certificate", "identifiers": ["localhost"]}
2022/03/02 04:42:12.786	INFO	tls	cleaning storage unit	{"description": "FileStorage:/root/.local/share/caddy"}
2022/03/02 04:42:12.787	INFO	tls	finished cleaning storage units
2022/03/02 04:42:12.794	WARN	pki.ca.local	installing root certificate (you might be prompted for password)	{"path": "storage:pki/authorities/local/root.crt"}
2022/03/02 05:42:12 not NSS security databases found
2022/03/02 05:42:12 define JAVA_HOME environment variable to use the Java trust
2022/03/02 04:42:12.794	ERROR	pki.ca.local	failed to install root certificate	{"error": "install is not supported on this system", "certificate_file": "storage:pki/authorities/local/root.crt"}
2022/03/02 04:42:12.795	INFO	autosaved config (load with --resume flag)	{"file": "/root/.config/caddy/autosave.json"}
Caddy proxying https://localhost -> http://127.0.0.1:8080

When you run caddy reverse-proxy, it doesn’t use any config file, so it just does a simple HTTPS proxy.

Instead, you’ll want to make a complete Caddyfile (the tutorials in our docs will get you started using templates with the Caddyfile, even - check them out!). Then use caddy run.

The Caddyfile you posted, if used, would only try to serve a site at https://templates that does nothing. You’ll also need to enable templates with the templates directive, and of course the file server to serve static files. Please be sure to read the Getting Started and Caddyfile tutorials at least! :slight_smile:

1 Like

Thank you, I had read around, some of the things just don’t seem very clear to me. Why using caddy run with Caddyfile reverse_proxy would work but not just running it directly from the command-line.
Any ways, for other people looking at this, wondering the same, this is what I changed my Caddyfile to:

localhost

templates
reverse_proxy 127.0.0.1:8080

Which seems to work as intended. The reverse proxy and templating is now working.

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.