How to get CountryName and pass as header to upstream

1. caddy:2.4.2-alpine

2. How I run Caddy:

I run caddy as docker container

b. Command:

CMD ["caddy", "run"]

d. My complete Caddyfile or JSON config:

localhost:80, home.so: {     
    route * {
        geoip '/etc/caddy/databases/geo.mmdb'
        reverse_proxy http://192.168.1.101:3000 {
            header_up custom-header test
            header_up Country-Name {geoip_country_name}
        }
    }

}

3. The problem I’m having:

I wanna get the user country name based on their request and pass it to the upstream as a header. i am trying to use this plugin but it does not work, also I saw in the portal that some people said about building geo-ip not sure if this still exists in v2. however, when I use that plugin I get errors. I am most wondering
how can i do this in Caddy v2?
fyi, the path of db is correct

4. Error messages and/or full log output:

2021/11/04 12:53:07.424 INFO    using adjacent Caddyfile
2021/11/04 12:53:07.426 WARN    input is not formatted with 'caddy fmt' {"adapter": "caddyfile", "file": "Caddyfile", "line": 1}
2021/11/04 12:53:07.431 INFO    admin   admin endpoint started  {"address": "tcp/localhost:2019", "enforce_origin": false, "origins": ["[::1]:2019", "127.0.0.1:2019", "localhost:2019"]}
2021/11/04 12:53:07.432 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc00048a000"}
2021/11/04 12:53:07.432 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}
2021/11/04 12:53:07.432 INFO    http    enabling automatic HTTP->HTTPS redirects        {"server_name": "srv0"}
2021/11/04 12:53:07.432 INFO    http    server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server {"server_name": "srv1", "http_port": 80}
2021/11/04 12:53:07.432 INFO    tls.cache.maintenance   stopped background certificate maintenance      {"cache": "0xc00048a000"}
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 handler modules: position 0: loading module 'subroute': provision http.handlers.subroute: setting up subroutes: route 0: loading handler modules: position 0: loading module 'geoip': provision http.handlers.geoip: geoip: Can't open database: '/etc/caddy/databases/geo.mmdb'

Please upgrade to v2.4.5!

Are you sure you mounted or added the database to your Docker container?

How are you building Caddy with the plugin?

Ultimately, this is a question about a third party plugin, the question is best asked on the github repo for that plugin, where the maintainer is more likely to see the question.

Edit: I’m confused, actually. You might have the wrong plugin? See this one:

1 Like

Thanks for reply @francislavoie

I will update my docker container version, and yes I am pretty sure that my DB file is added to my container. The problem with caddy-maxmind-geolocation is that it only used to filter requests by countries however my problem is to Add country name to the header and send this to backend. The plugin as far as I understand dose not expose any geo placeholder.

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