Is remote_ip bundled in V2?

1. My Caddy version (caddy version):

~ # ./caddy version
v2.0.0-rc.3 h1:z2H/QnaRscip6aZJxwTbghu3zhC88Vo8l/K57WUce4Q=

2. How I run Caddy:

a. System environment:

Ubuntu 18.04

b. Command:

./caddy adapt --config Caddyfile --pretty --validate      

d. My complete Caddyfile or JSON config:

{
debug
}

@all_hosts {
remote_ip 0.0.0.0/0
}

@lan_hosts {
remote_ip 192.168.10.0/24 192.168.20.0/24
}

http://site2.example.com:19500 {
    reverse_proxy * localhost:8081
}

3. The problem I’m having:

I am slowly building my JSON config file by turning a Caddy file into JSON, I now wanted to add IP filtering. The idea is that a named matcher would in one case allow everyone (0.0.0.0/0) and in the other only my LAN IP ranges:

When trying the Caddyfile above I get an error aboute remote_ip not being recignized

4. Error messages and/or full log output:

./caddy adapt --config Caddyfile --pretty --validate                                                                                                                       
adapt: Caddyfile:6: unrecognized directive: remote_ip

Is there something specific I need to do to have this directive recognized?

The issue is that you can’t define matcher blocks outside of a site block.

Right now the Caddyfile parser is reading @all_hosts as a site label, which means it will parse the contents of that block as regular directives and not as a matcher. We can definitely improve the error message in this situation. I recommend you go take a look at the Caddyfile structure documentation to get a clearer picture of how this works.

Also, matchers don’t do anything unless they’re tied to a specific handler directive, for example reverse_proxy @all_hosts localhost:8081

See this page for an overview of the structure of the Caddyfile: Caddyfile Concepts — Caddy Documentation

As Francis said, all your matchers have to go inside site blocks.

Yes, the documentation is actually very clear on that - I somehow missed the details.

Since I am going to ultimately work with JSON I now use a Caddyfile which I run though caddy adapt to understand what it means in JSON.

1 Like

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