Nginx - IP

Page content

sometimes, you wanna restrict access to a webserver based on ip addresses. here a little howto.

Update nginx Config for your vhost

and forward temporary/permanent to a sorry host.

--->8- snip -8<---

    location / {
      allow 192.0.2.0/24;
      allow 2001:db8::/32;
      deny all;
      error_page 403 =301 https://sorry.your.domain;
    }

or move the ip’s to a dedicated file and include it here …

--->8- snip -8<---

    location / {
      include incl/admin_ip.txt;
      deny all;
      error_page 403 =301 https://sorry.your.domain;
    }

Admin IP’s

cat ../incl/admin_ip.txt

allow 192.0.2.0/24;
allow 2001:db8::/32;

don’t forget to check your config and restart the webserver

nginx -t && rcctl restart nginx

Any Comments ?

sha256: 150d2114c929c1e1c7a4eb415a0e61e8203dbdc2f2faf159683476e4d8868a3d