Deny access to a PHP file (Nginx)

Posted by Desmond Hume on Stack Overflow See other posts from Stack Overflow or by Desmond Hume
Published on 2012-12-01T16:41:45Z Indexed on 2012/12/01 17:03 UTC
Read the original article Hit count: 139

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about linux