I have a / admin directory, and I want to block access to the directory and files inside the directory whenever anyone accesses through the public IP address. Here is my setup:
location /admin/ { allow 192.168.0.0/24; deny all; }
This works great when accessing the directory, however, if someone specifically accesses the file inside the directory (for example, url = "../admin/adminer.php), it does not restrict access to the file. I also tried other settings, such as:
location ~ /admin/.*$ { allow 192.168.0.0/24; deny all; }
It seems that this works when access is denied when accessing the public IP address, however, php code no longer works when accessing via the internal IP address, the PHP code is simply displayed as plain text.
The rest of the directives of my location are given here if they somehow influence the behavior:
location / { try_files $uri $uri/ /index.php?args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_cache_bypass $skip_cache; fastcgi_no_cache $skip_cache; fastcgi_cache WORDPRESS; fastcgi_cache_valid 60m; }
Hope someone can help me solve this problem.
source share