Deny access to a PHP file (Nginx)
- by Desmond Hume
I want Nginx to deny access to a specific PHP file, let's call it donotexposeme.php, but it doesn't seem to work, the PHP script is run as usual. Here is what I have in the config file:
location / {
root /var/www/public_html;
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/public_html$fastcgi_script_name;
include fastcgi_params;
}
location /donotexposeme.php {
deny all;
}
Of course, I do sudo service nginx reload (or restart) each time I edit the config.