1

Hello i try to deny access for externe IP to my URL admin.php of my website with nginx.

I have a jirafeau server with a example.com/admin.php I try to deny acces for this page but dont work. I am new with nginx this is my conf :

location / { try_files $uri $uri/ /admin.php; deny all; allow X.X.X.X/24; }

this deny all the externe ip of my website i just need deny acces to admin.php

thx for the help!

1 Answers1

1

NGINX Short Solve:

You can use either:

  • Example 1 (should work)
    location = /admin.php {
        deny all;
        allow 10.0.0.0/8; }
  • Example 2 (I'm unsure if it's the proper one for this case)
location ~* admin.php {
        deny all;
        allow 10.0.0.0/8; } 
  • Example 3 Combined with Basic-Auth
    location = /admin.php {
        deny all;
        allow 10.0.0.0/8; }
        auth_basic              "restricted area";
        auth_basic_user_file    /etc/nginx/htpw/.htpasswd;

  • Example 4 Basic-Auth only.
    location = /admin.php {
        auth_basic              "restricted area";
        auth_basic_user_file    /etc/nginx/htpw/.htpasswd;

Remind that your Browser-Cache can tricky yourself if it's not working directly (if you didn't forgot to reload nginx, of course.)

Reference:

  1. Stackoverflow
djdomi
  • 1,599
  • 3
  • 12
  • 19