leev / ngx_http_geoip2_module

Nginx GeoIP2 module
BSD 2-Clause "Simplified" License
961 stars 182 forks source link

Redirection not happening #103

Closed rmhaustralia closed 2 years ago

rmhaustralia commented 2 years ago

Hi, I'm trying to muddle my way through setting up geo blocking. I've managed to compile the module, but now nginx starts and the rest of my configure works, but the ngx_http_geoip2_module sections seem to have no effect. That is to say, no redirection is happening.

note: I've used X-Forwarded-For to get the real IP address of the client, as I'm running in Azure.

load_module /home/etc/nginx/modules/ngx_http_geoip2_module.so;
....

http {
    geoip2 /etc/GeoIP2-Country.mmdb {
        $current_client_ip X-Forwarded-For;
        $geoip2_data_country_code default=AU source=$current_client_ip country iso_code;
    }

    map $geoip2_data_country_code $allowed_country {
        default yes;
        BE no;
        BG no;
        CZ no;
    }
    ....

    server {
        if ($allowed_country = no) {
                return 302 https://www.google.com;
        }
        ....
    }

Any ideas on where I'm going wrong?

rmhaustralia commented 2 years ago

I've spent more time on this issue and worked it out. Thank you! :)

foozmeat commented 2 years ago

I've spent more time on this issue and worked it out. Thank you! :)

Would you mind posting your solution? I'm facing a similar issue.