<div dir="ltr"><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">I suggest you put the generic \.php$ regex location into the / default prefix location, like :<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">location / {<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">    location \.php$ {<br>        [...]<br>    }<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">}<br><br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">This avoids having regex location at the first level, since they are sensitive to order.<br><br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">Why using regex locations for individual files? The following would be more efficient:<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">location /myfile.php {<br>    [...]<br>}<br><br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">I also suggest you move redundant directives to the upper level whenever possible, this will help maintenance.<br></div><div class="gmail_extra"><div><div class="gmail_signature"><font size="1"><span style="color:rgb(102,102,102)">---<br></span><b><span style="color:rgb(102,102,102)">B. R.</span></b><span style="color:rgb(102,102,102)"></span></font></div></div>
<br><div class="gmail_quote">On Thu, Jan 8, 2015 at 11:49 PM, carlg <span dir="ltr"><<a href="mailto:nginx-forum@nginx.us" target="_blank">nginx-forum@nginx.us</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Here is what i found to achieve this :<br>
<br>
i denied access to every php files :<br>
<br>
 location ~ \.php$ {<br>
        fastcgi_split_path_info ^(.+\.php)(/.+)$;<br>
        fastcgi_pass unix:/var/run/php5-fpm.sock;<br>
        fastcgi_index index.php;<br>
        include fastcgi_params;<br>
        allow 127.0.0.1;<br>
        deny all;<br>
      }<br>
<br>
<br>
and then i create one rule per page (takes time with some scripts, but it<br>
worth it :)<br>
<br>
location ~* ^/myfile.php$ {<br>
 fastcgi_split_path_info ^(.+\.php)(/.+)$;<br>
 try_files $uri $uri/ /index.php?q=$args;<br>
fastcgi_pass unix:/var/run/php5-fpm.sock;<br>
fastcgi_index index.php;<br>
include fastcgi_params;<br>
include /etc/nginx/naxsi.rules;<br>
allow all;<br>
}<br>
<br>
Every tutorials i found on nginx tell us to allow / deny in location /.<br>
...but  ^(.+\.php) is another location, not included in location /<br>
<br>
If i follow most tutorials i am still able to reach the php files inside the<br>
location / even if i denied access to all of them.  Doing this way works<br>
great :)<br>
<br>
I hope this will help someone ... ...someday  :)<br>
Cheers :)<br>
<br>
Posted at Nginx Forum: <a href="http://forum.nginx.org/read.php?2,254785,256007#msg-256007" target="_blank">http://forum.nginx.org/read.php?2,254785,256007#msg-256007</a><br>
<br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</blockquote></div><br></div></div>