<div dir="ltr">while i request files <div><a href="http://domain.com/config.xml">http://domain.com/config.xml</a> </div><div>or </div><div><a href="http://domain.com/include/config.xml">http://domain.com/include/config.xml</a><div>both files downloaded, which is not good, </div></div><div><br></div><div>simple ~* /\.(tpl|xml)$ {return 404;}</div><div>works perfect but blocks files everywhere.</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 3, 2016 at 2:07 PM, Francis Daly <span dir="ltr"><<a href="mailto:francis@daoine.org" target="_blank">francis@daoine.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sat, Dec 03, 2016 at 12:19:44PM +0000, Musta Fa wrote:<br>
<br>
Hi there,<br>
<div><div class="h5"><br>
> im trying to create some regex just to match before second slash and only.<br>
> and allow all subfolders:<br>
><br>
> location ~ ^/([^/])+\.(tpl|xml)$ { return 404; }<br>
><br>
> these files are located in root folder, and i dont want them to be<br>
> downloaded,<br>
> but other files in subfolder are downloadable.<br>
><br>
> not sure why it not working?<br>
<br>
</div></div>Why do you think it is not working?<br>
<br>
What request do you make that you want to match this location, but it<br>
does not?<br>
<br>
What request do you make that you want not to match this location,<br>
but it does?<br>
<br>
Test:<br>
<br>
==<br>
  server {<br>
    listen 8888;<br>
    location ~ ^/([^/])+\.(tpl|xml)$ { return 200 "Did match: $uri\n"; }<br>
    location / { return 200 "Did not match: $uri\n"; }<br>
  }<br>
==<br>
<br>
$ curl <a href="http://127.0.0.1:8888/abc.xml" rel="noreferrer" target="_blank">http://127.0.0.1:8888/abc.xml</a><br>
Did match: /abc.xml<br>
$ curl <a href="http://127.0.0.1:8888/abc/def.xml" rel="noreferrer" target="_blank">http://127.0.0.1:8888/abc/def.<wbr>xml</a><br>
Did not match: /abc/def.xml<br>
$ curl <a href="http://127.0.0.1:8888/abc.txt" rel="noreferrer" target="_blank">http://127.0.0.1:8888/abc.txt</a><br>
Did not match: /abc.txt<br>
<span class="HOEnZb"><font color="#888888"><br>
        f<br>
--<br>
Francis Daly        <a href="mailto:francis@daoine.org">francis@daoine.org</a><br>
<br>
______________________________<wbr>_________________<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" rel="noreferrer" target="_blank">http://mailman.nginx.org/<wbr>mailman/listinfo/nginx</a><br>
</font></span></blockquote></div><br></div>