I want to deny access to one specific folder (and all files inside of it) but I'd like that php files from inside my server could have access to it (and its files). Is it possible? This is what I am trying without suvccess:

location /folder/ {
    allow;  # my server IP
    deny all;
    return 404;
  • 1
    If PHP is on the same server as the files then file access has nothing to do with your webserver. Oct 9 '11 at 10:01
  • You are so right. A simple php fileopen or include did the job. And the rule above still protect the files from being accessed inside the folder. Thank you.
    – Roger
    Oct 9 '11 at 11:50

The ACLs you set up in the nginx-configuration, is for the http-requests that will be served by nginx. If PHP wants to access other files, it is not constrained by the configuration of nginx. PHP however, can be constrained by its own configuration.

Since you want to move some security to PHP, I want to note that PHP may have access to configuration files and the likes. So you should make sure that you don't allow code like this to give any useful information to an attacker:


In the reality, this is what worked for me:

location ~ folder/ {
            allow;  #server IP
            deny all;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.