Re: Как запретить отдачу файлов из location?
    Max Ivanov 
    ivanov.maxim на gmail.com
       
    Ср Янв 19 22:01:52 MSK 2011
    
    
  
> Тут только через if, т.е. как-то так:
>
>    location / {
>        if (-f $request_filename) {
>            return 403;
>        }
>
>        ... pass to drupal here ...
>    }
Вот-вот :) Похожим образом изначально и было:
if (!-e $request_filename) {
  rewrite ^/(.*)$ /index.php?q=$1;
}
От чего всюду настоятельно рекомендуется отказываться. try_files
выглядят красиво но позволяют качать чего попало, а потом ограничивать
это регэкспами замучаешься.
Пришел вот к такому конфигу, для drupal,
позволяет иметь краткий whitelist файлов (туда занес картинки, сss и
скрипты что идут с модулями),
а также путь откуда можно качать все что угодно, не прописывая
расширения, при этом все иные существующие файлы будут возвращать 403
а несуществующие пути уходить на PHP:
server {
        server_name site1.domain.com;
        listen .....
        #Directory for logs must exist before you activate it
        access_log  /var/log/nginx/sites/site1/access.log detailed;
        error_log  /var/log/nginx/sites/site1/error.log info;
        root /data/sites/site1/htdocs/;
        #include settings/maintenance.conf;
        include settings/aux_loc.conf;
        location =/ {
                index index.php
        }
        location / {
              if (!-e $request_filename) {
                    rewrite ^/(.*)$ /index.php?q=$1;
              }
                return 403;
        }
        #drupal have limited ammount of php files which are called directly
        location = /index.php {
                include /etc/nginx/settings/fastcgi.conf;
                fastcgi_pass php_upstream1;
        }
        location = /update.php {
                auth_basic            "Restricted";
                auth_basic_user_file  deployment.htpasswd;
                include /etc/nginx/settings/fastcgi.conf;
                fastcgi_pass php_upstream1;
        }
        #Make ImageCache to work properly
        location /sites/all/files/imagecache/ {
                try_files $uri @drupal;
        }
        #Allow downloads of all files placed there by Drupal
        location /sites/all/files/ {
        }
        #Allow download files which usually comes with various modules
        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        }
}
Буду рад конструктивной критике :)
    
    
Подробная информация о списке рассылки nginx-ru