Error during parsing: Unexpected EOF

1. Caddy version (2):

2. How I run Caddy:

b. Command:

I run caddy in a compose file;

entrypoint:
    - caddy
    - run
    command:
    - --config=/etc/caddy/Caddyfile
    - --adapter=caddyfile

d. My complete Caddyfile or JSON config:

{
        #debug
        admin off
        log {
                level INFO
                format json
                output stderr
        }
}

:80 {
        root * /home
        log {
                level INFO
                format json
                output stdout
        }
        encode * gzip zstd
        @api_ab {
                path /dl
                path /dl/*
                path /admin
                path /admin/*
                path /api/v1
                path /api/v1/*
        }
        @api_m {
                path /api/v1/m
                path /api/v1/m/*
        }
        @api_me {
                path /me
                path /me/*
        }
        @api_s {
                path /s
                path /s/*
        }
        @api_in {
                path /in
                path /in/*
        }
        @qa_auth {
                method GET
                path *
                query qa=auth
        }
        route {
                respond @api_ab invalid 410 {
                        close
                }
                respond @api_m invalid 410 {
                        close
                }
                respond @api_me invalid 410 {
                        close
                }
                respond @api_in invalid 410 {
                        close
                }
                respond @api_s invalid 410 {
                        close
                }

                handle @qa_auth {
                        basicauth @qa_auth bcrypt qa.fincompare.de {
                                finstaging <trimmed key for privacy>
                        }
                        rewrite * /headers
                        respond * "granted" 200 {
                                close
                        }
                        # for debugging locally
                        #reverse_proxy https://httpbin.org {
                        #       header_up Host httpbin.org
                        #}
                }
                handle /health {
                        respond * 200 {
                                body "okay"
                                close
                        }
                }
                handle * {
                        try_files {path} {path}/ /{$INDEX:index.html}?{query}
                        file_server * {$BROWSE:browse} {
                                root {http.vars.root}
                                index {$INDEX:index.html}
                        }
                }
        }
        handle_errors {
                respond "{http.error.status_code} {http.error.status_text}"
                # for debugging locally
                #rewrite * /{http.error.status_code}
                #reverse_proxy https://http.cat {
                {
                        #debug
                        admin off
                        log {
                                level INFO
                                format json
                                output stderr
                        }
                }

                :80 {
                        root * /home
                        log {
                                level INFO
                                format json
                                output stdout
                        }
                        encode * gzip zstd
                        @api_fc-app {
                                path /dl
                                path /dl/*
                                path /admin
                                path /admin/*
                                path /api/v1
                                path /api/v1/*
                        }
                        @api_m {
                                path /api/v1/m
                                path /api/v1/m/*
                        }
                        @api_me {
                                path /me
                                path /me/*
                        }
                        @api_s {
                                path /s
                                path /s/*
                        }
                        @api_in {
                                path /in
                                path /in/*
                        }
                        @qa_auth {
                                method GET
                                path *
                                query qa=auth
                        }
                        route {
                                respond @api_ab invalid 410 {
                                        close
                                }
                                respond @api_m invalid 410 {
                                        close
                                }
                                respond @api_me invalid 410 {
                                        close
                                }
                                respond @api_in invalid 410 {
                                        close
                                }
                                respond @api_s invalid 410 {
                                        close
                                }

                                handle @qa_auth {
                                        basicauth @qa_auth bcrypt qa.fincompare.de {
                                                finstaging <trimmed key for privacy>
                                        }
                                        rewrite * /headers
                                        respond * "granted" 200 {
                                                close
                                        }
                                        # for debugging locally
                                        #reverse_proxy https://httpbin.org {
                                        #       header_up Host httpbin.org
                                        #}
                                }
                                handle /health {
                                        respond * 200 {
                                                body "okay"
                                                close
                                        }
                                }
                                handle * {
                                        try_files {path} {path}/ /{$INDEX:index.html}?{query}
                                        file_server * {$BROWSE:browse} {
                                                root {http.vars.root}
                                                index {$INDEX:index.html}
                                        }
                                }
                        }
                        handle_errors {
                                respond "{http.error.status_code} {http.error.status_text}"
                                # for debugging locally
                                #rewrite * /{http.error.status_code}
                                #reverse_proxy https://http.cat {
                                #       header_up Host http.cat
                                #}
                        }
                }

3. The problem I’m having:

Upon restart of services, caddy does not validate the caddy config and throws following error.

4. Error messages and/or full log output:

run: adapting config using caddyfile: /etc/caddy/Caddyfile:196 - Error during parsing: Unexpected EOF

5. What I already tried:

I tried doing caddy fmt and before this, I was getting error such as the following;

Caddyfile:50 - Error during parsing: Unexpected next token after '{' on same line

Maybe you have created the Caddyfile in windows and the line endings are windows line endings and not unix line endings.
Try to save the Caddyfile with LF instead of CRLF, it’s just a guess.

Start by removing bits of config one chunk at a time until it works. You can narrow down which part is causing the issue.

1 Like