Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx maintainence page with ip whitelist

For my site I'd like to be able to put up a maintenance 503 page but with a whitelist of ip-addresses that will be able to use the website as normal

Would I have to craft something like this in lua?

I see some questions like

Nginx Ip Whitelist

and

How can I setup a custom 503 error page in NGINX?

which explain how to do this separately but I'd like to kind of combine them so I could take the site offline for the outside world but still be able to test it normally from certain IP addresses

like image 396
Neil Avatar asked Oct 25 '25 08:10

Neil


1 Answers

You could use the ngx_http_geo_module:

geo $denied {
    default 1; # nobody is allowed access by default

    # but people from the following networks/ip addresses are allowed access
    include whitelist;
    127.0.0.1      0;
    192.168.1.0/24 0;
}

server {
    location / {
        if ($denied) {
            return 503;
        }
    }
}
like image 126
Cole Tierney Avatar answered Oct 27 '25 01:10

Cole Tierney



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!