Welcome! Log In Create A New Profile

Advanced

Restrict files

Posted by siloan 
Restrict files
September 30, 2011 06:10PM
Hi there, i'm trying to deny some specified files like
location ^~ /doc([0-9]+)/inc/file.php { deny all; }
where doc can be accesed in url like mydomain.com/doc1 doc2 etc but this isn't working, in fact the regex part isn't working and i don't know why - doc([0-9]+) should be correct.
Re: Restrict files
October 25, 2011 06:38AM
Still interested about this.
Re: Restrict files
October 25, 2011 04:36PM
Hi,

try:

location ~ /doc\d+/inc/file\.php {
deny all;
}

and put it as a sub-location into your \.php location handler.

Andrejs



Edited 1 time(s). Last edit at 10/25/2011 04:37PM by locojohn.
Re: Restrict files
October 26, 2011 08:07AM
Great man, thanks! 2 more questions:
1.How to restrict only .php files in that way.
2.I have a rewrite
rewrite ^/doc([0-9]+)$ /doc/index.php?d=$1 last;
mydomain.com/doc1 is working but if the link has a ending slash like mydomain.com/doc1/ is not working anymore, why ?
Re: Restrict files
October 26, 2011 08:13AM
siloan Wrote:
-------------------------------------------------------
> Great man, thanks! 2 more questions:
> 1.How to restrict only .php files in that way.
> 2.I have a rewrite
> rewrite ^/doc([0-9]+)$ /doc/index.php?d=$1 last;
> mydomain.com/doc1 is working but if the link has a
> ending slash like mydomain.com/doc1/ is not
> working anymore, why ?


because in your rewrite rule the dollar sign matches end of string, meaning the url always ends with digits.

try:

rewrite ^/doc\d+ /doc/index.php?d=$1 last;

Andrejs
Re: Restrict files
October 26, 2011 08:38AM
Ok but now the hole link is shown in the browser like http://mydomain.com/doc1/index.php?d=1
Re: Restrict files
October 26, 2011 08:44AM
siloan Wrote:
-------------------------------------------------------
> Ok but now the hole link is shown in the browser
> like http://mydomain.com/doc1/index.php?d=1

Maybe this:

rewrite ^/doc\d+/?$ /doc/index.php?d=$1 last;

Andrejs
Re: Restrict files
October 26, 2011 09:05AM
Now isn't working at all.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 316
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready