Welcome! Log In Create A New Profile

Advanced

Allow only certain file types

Posted by fmyoen 
Allow only certain file types
April 06, 2012 10:29AM
Hi, I'm trying to set up the configuration described in subject. I found for example this thread http://forum.nginx.org/read.php?2,61581,61740. This is what they advice:

> 1) all requests for particular extensions and directories to be served
> 2) everything else to return 444
>
> location ~ (/?|\.html|\.jpg|\.php|\.png|\.css|\.ico|\.js|\.swf|\.gif|robots\.txt)$ {
> ...
> }
>
> location / { return 444; }

As far as I understand this configuration doesn't work. First of all "(/?)$" in the regexp above means "anything that not nessecerily ends with /", so basically it's just anything, so access to any file or directory is still allowed. It almost works in case we remove "?":

location ~ (/|\.html|\.jpg|\.php|\.png|\.css|\.ico|\.js|\.swf|\.gif|robots\.txt)$

The problem is that this regex blocks access to all directories that were specified without trailing "/": user will got 444 trying to open http://site.com/dir but not http://site.com/dir/.

Do you have any ideas how to solve this problem?



Edited 3 time(s). Last edit at 04/06/2012 10:31AM by fmyoen.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 163
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