Q: about try_files and regex location

Maxim Dounin mdounin at mdounin.ru
Fri Nov 11 13:18:27 UTC 2011


Hello!

On Fri, Nov 11, 2011 at 01:16:25PM +0100, Aleksandar Lazic wrote:

> Dear all,
> 
> please can you help me to fix the issue with try_files an regex
> location, thank you.
> 
> I use
> 
> ###
> sbin/nginx -V
> nginx: nginx version: nginx/1.1.4
> nginx: built by gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5)
> nginx: TLS SNI support enabled
> nginx: configure arguments: --with-debug --with-libatomic
> --without-http_ssi_module --without-http_uwsgi_module
> --without-http_scgi_module --without-http_memcached_module
> --with-http_ssl_module --user=nginx --group=nginx
> --prefix=server/nginx --with-http_stub_status_module
> ###
> 
> with the following config.
> 
> ###
> http {
>   server {
> ...
>         location ~ ^/(share|alfresco)(/res)?(.*$)  {
>           alias /home/alfresco/alfresco-4.0.b/tomcat/webapps;
>           try_files $uri /$1$2 /$1$3 @alfresco;
>         }
> 
>         location @alfresco {
>           proxy_pass   http://alfresco;
>         }
>   }
> }
> ###
> 
> I get the following error:
> 
> ###
> 2011/11/11 12:58:09 [error] 5618#0: *33782 open()
> "/home/alfresco/alfresco-4.0.b/tomcat/webapps/share/components/document-details/document-link/home/al"
> failed (2: No such file or directory), client: xxx, server: xxx,
> request: "GET
> /share/components/document-details/document-links-min.js HTTP/1.1",
> host: "xxx", referrer: "https://xxx/share/page/site/aleks-glossar/document-details?nodeRef=workspace://SpacesStore/985297e8-ff1b-4423-b6e9-8dacc0011196"
> ###
> 
> Could it be that try_files match on '/$1$2' but the open call get
> '/$1$3' or something else?
> 
> attached the debug log.

This is the bug in alias and try_files interaction.  Or, more 
strictly, such configuration should be rejected during testing 
configuration as it's not really make sense: alias within regex 
location specifies full path to a file, and try_files is 
meaningless here.

You probably mean to use "root" instead, i.e.

    location ~ ^/(share|alfresco)(/res)?(.*$) {
        root /home/alfresco/alfresco-4.0.b/tomcat/webapps;
        try_files $uri /$1$2 /$1$3 @alfresco;
    }

Maxim Dounin



More information about the nginx mailing list