Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 1.2.3.4;  # my server IP
    deny all;
    return 404;
}
share|improve this question
1  
If PHP is on the same server as the files then file access has nothing to do with your webserver. –  Martin Fjordvald 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

2 Answers 2

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:

http://my.server.acme.org/images.php?file=../../../etc/passwd
share|improve this answer
up vote 0 down vote accepted

In the reality, this is what worked for me:

location ~ folder/ {
            allow 1.2.3.4;  #server IP
            deny all;
    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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