Caddyfiles get messy fast once a few people have edited them. Caddy ships its own formatter, so nobody has to fix indentation by eye.
caddy fmt --diff Caddyfile
The docs say caddy fmt formats or prettifies a Caddyfile and then exits. By default the result is printed to the terminal. With --diff (short form -d) the output is compared against the input, and lines are prefixed with - and + where they differ. So you see the change before you accept it.
When the diff looks fine, write it back:
caddy fmt --overwrite Caddyfile
The short form is -w. With --overwrite the result goes into the input file instead of the terminal. If you leave out the path, Caddy assumes a file named Caddyfile in the current directory. A path of - reads from stdin.
The detail I like most is the exit code. The docs say the command exits with code 1 if there are any differences. That makes it usable as a check in a script:
caddy fmt --diff Caddyfile || echo "Caddyfile needs formatting"
The caveat is that --overwrite really does rewrite your file. Keep the Caddyfile in version control, or at least look at the --diff output first.
Further reading: Caddy command line reference
Going deeper: Guide: fix a 502 Bad Gateway in Nginx Proxy Manager, with a checklist that finds the cause