exclude error_page on geoip

Maxim Dounin mdounin at mdounin.ru
Thu Nov 3 13:18:55 UTC 2016


On Thu, Nov 03, 2016 at 02:05:55PM +0800, Tseveendorj Ochirlantuu wrote:

> Hello,
> I need to use geoip module for allow specific region access to my website.
> But blocked users should see the error_page. Users are blocked and cannot
> see custom error_page.
> I don't want to see error_page from other domain. I need to except only
> error page which is not applied to geoip block.

Try something like this:

    server {
        listen 80;

        error_page 403 /403.html;

        location / {
            if ($blocked) {
                return 403;


        location = /403.html {
            # no geoip restrictions here

With such a configuration GeoIP-based restrictions are only 
applied in "location /", but doesn't affect requests to /403.html.
That is, nginx will be able to return the error page correctly.

Maxim Dounin

More information about the nginx mailing list