Inadvertent (?) V2 puts me dead in the water

1. The problem I’m having:

Without having updated my Caddyfile, I appear to have inadvertently upgraded to V2 (on Digital Ocean Ubuntu 20.04.5) and, in Firefox for https://theviewfromafar.com/ the message it gives is "unable to connect.
caddy version
v2.4.6 h1:HGkGICFGvyrodcqOOclHKfvJC0qTU7vny/7FhYp9hNw=
The previous version ran swimmingly for months.

2. Error messages and/or full log output:

root@viewfromafar:~# caddy stop
2023/03/02 17:16:51.592	WARN	failed using API to stop instance	{"error": "performing request: Post \"http://localhost:2019/stop\": dial tcp [::1]:2019: connect: connection refused"}
stop: performing request: Post "http://localhost:2019/stop": dial tcp [::1]:2019: connect: connection refused
root@viewfromafar:~# 
root@viewfromafar:~# caddy start
2023/03/02 17:17:17.457	INFO	using adjacent Caddyfile
2023/03/02 17:17:17.459	WARN	input is not formatted with 'caddy fmt'	{"adapter": "caddyfile", "file": "Caddyfile", "line": 2}
2023/03/02 17:17:17.461	INFO	admin	admin endpoint started	{"address": "tcp/localhost:2019", "enforce_origin": false, "origins": ["[::1]:2019", "127.0.0.1:2019", "localhost:2019"]}
2023/03/02 17:17:17.461	INFO	http	server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS	{"server_name": "srv0", "https_port": 443}
2023/03/02 17:17:17.461	INFO	http	enabling automatic HTTP->HTTPS redirects	{"server_name": "srv0"}
2023/03/02 17:17:17.464	INFO	tls.cache.maintenance	started background certificate maintenance	{"cache": "0xc000574cb0"}
2023/03/02 17:17:17.464	INFO	tls.cache.maintenance	stopped background certificate maintenance	{"cache": "0xc000574cb0"}
run: loading initial config: loading new config: loading http app module: provision http: server srv0: setting up route handlers: route 0: loading handler modules: position 0: loading module 'subroute': provision http.handlers.subroute: setting up subroutes: route 0: loading matcher modules: module name 'expression': provision http.matchers.expression: compiling CEL program: ERROR: <input>:1:57: Syntax error: extraneous input '||' expecting {'[', '{', '(', '.', '-', '!', 'true', 'false', 'null', NUM_FLOAT, NUM_INT, NUM_UINT, STRING, BYTES, IDENTIFIER}
 | caddyPlaceholder(request, "http.request.uri.query") ==  || caddyPlaceholder(request, "http.request.uri.query") == tab=links || caddyPlaceholder(request, "http.request.uri.query") == tab=about
 | ........................................................^
ERROR: <input>:1:118: Syntax error: token recognition error at: '=l'
 | caddyPlaceholder(request, "http.request.uri.query") ==  || caddyPlaceholder(request, "http.request.uri.query") == tab=links || caddyPlaceholder(request, "http.request.uri.query") == tab=about
 | .....................................................................................................................^
ERROR: <input>:1:120: Syntax error: mismatched input 'inks' expecting <EOF>
 | caddyPlaceholder(request, "http.request.uri.query") ==  || caddyPlaceholder(request, "http.request.uri.query") == tab=links || caddyPlaceholder(request, "http.request.uri.query") == tab=about
 | .......................................................................................................................^
ERROR: <input>:1:186: Syntax error: token recognition error at: '=a'
 | caddyPlaceholder(request, "http.request.uri.query") ==  || caddyPlaceholder(request, "http.request.uri.query") == tab=links || caddyPlaceholder(request, "http.request.uri.query") == tab=about
 | .........................................................................................................................................................................................^
start: caddy process exited with error: exit status 1
root@viewfromafar:~# 

3. Caddy version:

v2.4.6 h1:HGkGICFGvyrodcqOOclHKfvJC0qTU7vny/7FhYp9hNw=

4. How I installed and ran Caddy:

a. System environment:

Digital Ocean Ubuntu 20.04.5

b. Command:

caddy start

c. Service/unit/compose file:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.



d. My complete Caddy config:

theviewfromafar.com {
    @shouldRedir {
        path /sbwTweet
        expression {query} == "" || {query} == "tab=links" || {query} == "tab=about"
    }
    redir @shouldRedir http://theviewfromafar.com{uri}
             reverse_proxy http://oldschool.scripting.com {
                 header_up Host {upstream_hostport}
                 }
      log
    }  

5. Links to relevant resources:

In addition to reclaiming caddy as v2, to function I need to make this change:

in the Caddyfile path I need to change
/sbwTweet
to /
sbwaters@rnymedia.com


Also, while I love what you do, and have been a caddy supporter for some time now, I would dearly love to find a caddy/ubuntu poweruser sitting on the other side of a virtual office partition that I could call upon to roll up sleeves and assist. I ceased to be a programmer and a junior webmaster years ago and, at age 75, I need occasionally to be able to buy someone a virtual drink or two from time to time to log in, survey the landscape, save my ass. The time has come for me just to update and run webpages. Do you have pointers to powe rusers for hire?

1 Like

Please upgrade to the latest version, i.e. v2.6.4

Caddy is failing to start because of a syntax issue with your config.

The problem is that the double quoted (") parts are interpreted as Caddyfile tokens first, before it can be compiled as a CEL expression. Wrap the entire expression with backticks (`) to make sure the double quotes are preserved.

expression `{query} == "" || {query} == "tab=links" || {query} == "tab=about"`

I strongly recommend not using the caddy start and caddy stop commands. They’re meant for quick-and-dirty local development, not for long-running servers.

Instead, you should run Caddy as a systemd service. If you installed Caddy with our official instructions, it should already be set up for you to do so. See the docs:

My hat off to you! Seriously, much respect. Thank you for using Caddy. I hope at your age I’m still as tech-capable as you are :slight_smile: I wish I had a list of people we could recommend who are available for hire. That’s a great idea though, and I’ll see if we can make room for that with our new website and maybe a forum update.

Anyway, I think Francis’ answer will get you 90% of the way there, if not all the way, so let us know how that goes.

1 Like

Thank you so much for your help. We seem to be working although “caddy fmt” still indicates an error:
root@viewfromafar:/etc/caddy# caddy fmt
theviewfromafar.com {
redir /sbwaters@rnymedia.com/* The View from Afar
root * /var/www/tvfa
file_server
templates
log {
output file /var/log/access.log
format console
}
}
Error: Caddyfile:2: Caddyfile input is not formatted
root@viewfromafar:/etc/caddy# caddy validate
2023/03/05 21:46:26.635 INFO using adjacent Caddyfile
2023/03/05 21:46:26.638 WARN Caddyfile input is not formatted; run the ‘caddy fmt’ command to fix inconsistencies {“adapter”: “caddyfile”, “file”: “Caddyfile”, “line”: 2}
2023/03/05 21:46:26.641 INFO http server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS {“server_name”: “srv0”, “https_port”: 443}
2023/03/05 21:46:26.642 INFO http enabling automatic HTTP->HTTPS redirects {“server_name”: “srv0”}
2023/03/05 21:46:26.642 INFO tls.cache.maintenance started background certificate maintenance {“cache”: “0xc0003fe770”}
2023/03/05 21:46:26.643 INFO tls.cache.maintenance stopped background certificate maintenance {“cache”: “0xc0003fe770”}
Valid configuration

Thank you!

That’s not an error, it’s just a warning.

You need to use the --overwrite flag to have it update your config. Running it without --overwrite only writes the output to stdout.

Please use code blocks when posting your config and logs to the forums, you can use the </> button at the top of the text editor. Without it, whitespace isn’t preserved, which messes up the formatting.

You need to use the --overwrite flag to have it update your config.

https://caddyserver.com/docs/running#using-the-service offers the instruction:
If using a config file, you can gracefully reload Caddy after making any changes:

sudo systemctl reload caddy

but that reload using a new Caddyfile will have been corrected by Caddyfile fmt but not saved. Correct?

So one should run “caddy fmt --overwrite”, then “caddy validate”, and then “sudo systemctl reload caddy”

Thank you.

1 Like

Right, it won’t touch your config file when you reload. I just uses that config.

Sure. If your config is invalid, then the reload will fail and the previous config will be kept active, so you don’t really need to validate. You can just check the logs after reloading to make sure it worked.