Answer the question
In order to leave comments, you need to log in
How to deny access to all PHP files in Nginx, except for the 2 necessary ones in subdirectories?
Hello. Who can tell me how to write rules for nginx that would prohibit access to any \.(php|cgi|pl|phtml) files in a directory, say, /dir/apdir/, but would allow access to 2 PHP files in nested folders?
To make the question more clear, I will give an example:
If you need to allow access to only one file, the construction is as follows:
location ~ ^/dir/apdir/.+\.(php|cgi|pl|phtml)(?<!subdir/index\.php) {
deny all;
}
location ~ ^/dir/apdir/.+\.(php|cgi|pl|phtml)((?<!subdir/index\.php)|(?<!js/idexfile/file\.php)) {
deny all;
}
location ~ ^/(dir/apdir/subdir/index|dir/apdir/js/idexfile/file)\.php {
allow all;
}
location ~ ^/(dir/apdir)/.+\.(php|cgi|pl|phtml) {
deny all;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question