Welcome! Log In Create A New Profile

Advanced

Block all IPs except local network on specific locations.

Posted by mi6 
mi6
Block all IPs except local network on specific locations.
March 05, 2020 06:55AM
Hi,

I want to allow access to certain locations on my web server (e.g. phpMyAdmin) to local IPs only.

When using Apache, I had the following content in .htaccess:

----------------------------------------------------------------------------------------
RewriteEngine on

RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.*
RewriteRule ^phpMyAdmin($|/) - [L,R=403]

RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.*
RewriteRule ^phpvirtualbox($|/) - [L,R=403]

RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.*
RewriteRule ^Wiki($|/) - [L,R=403]
----------------------------------------------------------------------------------------

In an nginx conf file, I tried to solve the same as follows:

----------------------------------------------------------------------------------------
server {
listen 80;
server_name 192.168.1.110;

location /phpMyAdmin/ {
allow 192.168.1.0/24;
deny all;
}
}
----------------------------------------------------------------------------------------

This, however, doesn't seem to work - I get a 404 error. Does anyone know why? Also, I would like any denied IPs to be redirected to 403.

Any help is appreciated!

Thank you, MI6
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 220
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready