Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import snippet not working after bind #4570

Closed
eslym opened this issue Feb 11, 2022 · 7 comments
Closed

Import snippet not working after bind #4570

eslym opened this issue Feb 11, 2022 · 7 comments
Labels
question ❔ Help is being requested

Comments

@eslym
Copy link

eslym commented Feb 11, 2022

Caddy Version: v2.4.6 h1:HGkGICFGvyrodcqOOclHKfvJC0qTU7vny/7FhYp9hNw=

engshun@SHUN-LAPTOP:/etc/caddy$ cat Caddyfile
bind 127.0.0.1

(default_errors) {
    handle_errors {
        respond "{http.error.status_code} {http.error.status_text}"
    }
}

http:// {
        error * 418
        import default_errors
}
engshun@SHUN-LAPTOP:/etc/caddy$ caddy validate
2022/02/11 06:52:49.259 INFO    using adjacent Caddyfile
validate: adapting config using caddyfile: Caddyfile:11 - Error during parsing: File to import not found: default_errors
engshun@SHUN-LAPTOP:/etc/caddy$ 

but if i remove the bind

engshun@SHUN-LAPTOP:/etc/caddy$ cat Caddyfile
(default_errors) {
    handle_errors {
        respond "{http.error.status_code} {http.error.status_text}"
    }
}

http:// {
        error * 418
        import default_errors
}
engshun@SHUN-LAPTOP:/etc/caddy$ caddy validate
2022/02/11 06:53:23.044 INFO    using adjacent Caddyfile
2022/02/11 06:53:23.047 WARN    input is not formatted with 'caddy fmt' {"adapter": "caddyfile", "file": "Caddyfile", "line": 2}
2022/02/11 06:53:23.047 INFO    http    server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server     {"server_name": "srv0", "http_port": 80}
2022/02/11 06:53:23.047 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc0000c8000"}
2022/02/11 06:53:23.047 INFO    tls.cache.maintenance   stopped background certificate maintenance      {"cache": "0xc0000c8000"}
Valid configuration
engshun@SHUN-LAPTOP:/etc/caddy$ 
@francislavoie
Copy link
Member

francislavoie commented Feb 11, 2022

bind is a directive, it must go within a site block.

https://caddyserver.com/docs/caddyfile/concepts#structure

The reason you get that specific error is because Caddy reads bind and 127.0.0.1 as being your site addresses (domain names), which means anything that follows is read as being part of that site block, but it's not valid to define a snippet inside of a site block, so it breaks.

@francislavoie francislavoie added the question ❔ Help is being requested label Feb 11, 2022
@eslym
Copy link
Author

eslym commented Feb 11, 2022

bind is a directive, it must go within a site block.

https://caddyserver.com/docs/caddyfile/concepts#structure

The reason you get that specific error is because Caddy reads bind and 127.0.0.1 as being your site addresses (domain names), which means anything that follows is read as being part of that site block, but it's not valid to define a snippet inside of a site block, so it breaks.

why cant globaly bind to only 1 ip? i need to have different instance bound to different ip on local for testing purpose, i checked on the cli there is no options to only listen to specific ip also

Update
i tested, if I want caddy only listen to specific ip then i will need to add bind to every single site block, this is very inconvenient

@mohammed90
Copy link
Member

bind is a directive, it must go within a site block.

https://caddyserver.com/docs/caddyfile/concepts#structure

The reason you get that specific error is because Caddy reads bind and 127.0.0.1 as being your site addresses (domain names), which means anything that follows is read as being part of that site block, but it's not valid to define a snippet inside of a site block, so it breaks.

why cant globaly bind to only 1 ip? i need to have different instance bound to different ip on local for testing purpose, i checked on the cli there is no options to only listen to specific ip also

Update
i tested, if I want caddy only listen to specific ip then i will need to add bind to every single site block, this is very inconvenient

There will be default_bind global option in the Caddyfile in the next release. Implemented by @francislavoie in #4531.

@eslym
Copy link
Author

eslym commented Feb 14, 2022

bind is a directive, it must go within a site block.
https://caddyserver.com/docs/caddyfile/concepts#structure
The reason you get that specific error is because Caddy reads bind and 127.0.0.1 as being your site addresses (domain names), which means anything that follows is read as being part of that site block, but it's not valid to define a snippet inside of a site block, so it breaks.

why cant globaly bind to only 1 ip? i need to have different instance bound to different ip on local for testing purpose, i checked on the cli there is no options to only listen to specific ip also
Update
i tested, if I want caddy only listen to specific ip then i will need to add bind to every single site block, this is very inconvenient

There will be default_bind global option in the Caddyfile in the next release. Implemented by @francislavoie in #4531.

thanks, but i will be more glad if it is in the documentation

@francislavoie
Copy link
Member

It will be with the release of v2.5.0

@bcookatpcsd
Copy link

Hey there..

Random human here.. sorry to necrobump..

https://caddyserver.com/docs/caddyfile/options#default-bind

Just spent a bunch of time trying to figure out why this doesn't work..

Nothing says.. "coming in 2.5.0" on the official docs..

The commit reads:

4326d7b

default_bind tcp4/0.0.0.0

that syntax is also not shown in the official docs..

Thank you for your time..

@francislavoie
Copy link
Member

francislavoie commented Apr 20, 2022

The commit where it was merged is 1b7ff5d

The release notes https://github.com/caddyserver/caddy/releases/tag/v2.5.0-rc.1 do say:

Caddyfile: New default_bind global option lets you specify the default interface all sockets should bind to.

Docs are currently not versioned, we did push the v2.5.0 changes to the docs site early. See caddyserver/website#59

https://caddyserver.com/docs/caddyfile/options#default-bind that syntax is also not shown in the official docs..

That section links to the bind directive: https://caddyserver.com/docs/caddyfile/directives/bind; the syntax is outlined there. default_bind is the same as bind except acts as a global default, so it can be assumed the syntax is the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question ❔ Help is being requested
Projects
None yet
Development

No branches or pull requests

4 participants