I want to configure our nginx to be a little more paranoid concerning
file
access.
Right now, i am using rules like :
location /includes {
allow 127.0.0.1;
deny all;
}
… but i need to repeat this kind of rules for every folders, and then
restrict access to the php files inside. So our rules file is too long,
complicated and getting very messy. Also, this doesn’t protect the php
files, only the folders. so i need to add more and more rules, always.
The php files a visitor require to be able to reach directly are in /
(like
index.php, login.php, etc…)
I would like to restrict every other files to 127.0.0.1, and then add
some
rules to allow all traffic only where required.
But i cannot figure out how i can achieve this with nginx. I’m pretty
sure
there is a single rule that can do this.
Any help will be very appreciated, and may help may others i am sure to
be
more secure
Note that you have configure all required processing, not just
access rules. That is, for php files you’ll have to configure
fastcgi_pass/whatever as appropriate.
On Thu, Nov 13, 2014 at 03:33:03AM -0500, carlg wrote:
Hi,
It works, but i am still able to access the php files inside the restricted
directories. I tried with :
location /myfolder/(.+).php$ {
deny all;
}
But this doesn’t work!
If you followed what I suggested, you should not be able to access
anything unless it’s explicitly allowed. I suspect you’ve added
something like “location ~ .php$ { allow all; …}” - and this is
what causes your problems. Remove it, and start again with
exact match locations, as previously suggested.
Also, i cannot make this method work nice with our clean url’s. We are
using :
By introducing various rewriting in nginx configuration you make
your life harder. That’s your deliberate choice. Igor recently
gave a talk about this, see here:
Every tutorials i found on nginx tell us to allow / deny in location /.
…but ^(.+.php) is another location, not included in location /
If i follow most tutorials i am still able to reach the php files inside
the
location / even if i denied access to all of them. Doing this way works
great