Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Block all IPs except local network on specific locations.

$
0
0
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

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>