# Q: about try\_files and regex location

**URL:** <https://www.ruby-forum.com/t/q-about-try-files-and-regex-location/213788>\
**Category:** NGINX\
**Created:** [November 11, 2011, 1:17pm UTC](https://www.ruby-forum.com/t/q-about-try-files-and-regex-location/213788 "2011-11-11T13:17:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [November 11, 2011, 1:17pm UTC](https://www.ruby-forum.com/t/q-about-try-files-and-regex-location/213788/1 "2011-11-11T13:17:00Z")

</div>

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](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.

BR  
Aleks

#### debug

2011/11/11 12:58:09 [debug] 5618#0: \*33782 posix\_memalign:  
000000000CD7D350:4096 @16  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http process request line  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http request line: “GET  
/share/components/document-details/document-links-min.js HTTP/1.1”  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http uri:  
“/share/components/document-details/document-links-min.js”  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http args: “”  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http exten: “js”  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http process request header  
line  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http header: “Host: XXXX”  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http header: “User-Agent:  
Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2”  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http header: “Accept: _/_”  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http header:  
“Accept-Language: de-de,de;q=0.8,en;q=0.5,en-us;q=0.3”  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http header:  
“Accept-Encoding: gzip, deflate”  
2011/11/11 12:58:09 [debug] 5618#0: _33782 http header:  
"Accept-Charset: UTF-8,_"  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http header: “DNT: 1”  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http header: “Referer:  
[https://xxx/share/page/site/aleks-glossar/document-details?nodeRef=workspace://SpacesStore/985297e8-ff1b-4423-b6e9-8dacc0011196](https://xxx/share/page/site/aleks-glossar/document-details?nodeRef=workspace://SpacesStore/985297e8-ff1b-4423-b6e9-8dacc0011196)”  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http header: “Cookie:  
JSESSIONID=C3A5E3E0985A055C732E884981544337; alfLogin=1321012572;  
alfUsername2=“YWxyaXQ=””  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http header: “Connection:  
keep-alive”  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http header done  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 event timer del: 7:  
1321012754907  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 rewrite phase: 0  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 test location: “/redmine”  
2011/11/11 12:58:09 [debug] 5618#0: _33782 test location: ~  
"^/(share|alfresco)(/res)?(._$)"  
2011/11/11 12:58:09 [debug] 5618#0: _33782 using configuration  
"^/(share|alfresco)(/res)?(._$)"  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http cl:-1 max:52428800  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 rewrite phase: 2  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 post rewrite phase: 3  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 generic phase: 4  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 generic phase: 5  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 access phase: 6  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 access phase: 7  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 post access phase: 8  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 try files phase: 9  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http script copy:  
“/home/alfresco/alfresco-4.0.b/tomcat/webapps”  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http script var:  
“/share/components/document-details/document-links-min.js”

2011/11/11 12:58:09 [debug] 5618#0: \*33782 trying to use file:  
“/share/components/document-details/document-links-min.js”  
“/home/alfresco/alfresco-4.0.b/tomcat/webapps/share/components/document-details/document-links-min.js”

2011/11/11 12:58:09 [debug] 5618#0: \*33782 try file uri:  
“/share/components/document-details/document-links-min.js”  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 content phase: 10  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 content phase: 11  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 content phase: 12  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http script copy:  
“/home/alfresco/alfresco-4.0.b/tomcat/webapps”

2011/11/11 12:58:09 [debug] 5618#0: \*33782 http filename:  
“/home/alfresco/alfresco-4.0.b/tomcat/webapps/share/components/document-details/document-link/home/al”

2011/11/11 12:58:09 [debug] 5618#0: \*33782 add cleanup:  
000000000CD7DF38  
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://external.none.at/share/page/site/aleks-glossar/document-details?nodeRef=workspace://SpacesStore/985297e8-ff1b-4423-b6e9-8dacc0011196](https://external.none.at/share/page/site/aleks-glossar/document-details?nodeRef=workspace://SpacesStore/985297e8-ff1b-4423-b6e9-8dacc0011196)”  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http finalize request: 404,  
“/share/components/document-details/document-link/home/al?” a:1, c:1  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http special response: 404,  
“/share/components/document-details/document-link/home/al?”  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http set discard body  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 HTTP/1.1 404 Not Found  
Server: nginx/1.1.4  
Date: Fri, 11 Nov 2011 11:58:09 GMT  
Content-Type: text/html  
Content-Length: 168  
Connection: keep-alive

2011/11/11 12:58:09 [debug] 5618#0: \*33782 write new buf t:1 f:0  
000000000CD7DFB8, pos 000000000CD7DFB8, size: 154 file: 0, size: 0  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http write filter: l:0 f:0  
s:154  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http output filter  
“/share/components/document-details/document-link/home/al?”  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 http copy filter:  
“/share/components/document-details/document-link/home/al?”  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 write old buf t:1 f:0  
000000000CD7DFB8, pos 000000000CD7DFB8, size: 154 file: 0, size: 0  
2011/11/11 12:58:09 [debug] 5618#0: \*33782 write new buf t:0 f:0  
0000000000000000, pos 00000000006802C0, size: 116 file: 0, size: 0

####

---

<div class="post-metadata">

**Author:** ![Aleksandar\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8edcca/32.png) [@Aleksandar\_L](https://www.ruby-forum.com/u/Aleksandar_L)\
**Post date:** [November 11, 2011, 2:15pm UTC](https://www.ruby-forum.com/t/q-about-try-files-and-regex-location/213788/2 "2011-11-11T14:15:45Z")

</div>

On Friday 11 November 2011 16:16:25 Aleksandar L. wrote:  
[…]

> ### 
> 
> http {  
> server {  
> …  
> location ~ ^/(share|alfresco)(/res)?(.\*$) {

- location ~ ^/(share|alfresco)(/res)?(.\*$) {

- location ~ ^/(share|alfresco)(/res)?(.\*)$ {

> ```
> alias /home/alfresco/alfresco-4.0.b/tomcat/webapps;
> 
> ```

[…]

> **[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#alias)**
>
> This directive appeared in version 1.11.8.

The “alias” directive in your config replaces request part of path to  
file after  
successful “try\_files” check.

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![Aleksandar\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8edcca/32.png) [@Aleksandar\_L](https://www.ruby-forum.com/u/Aleksandar_L)\
**Post date:** [November 12, 2011, 12:14am UTC](https://www.ruby-forum.com/t/q-about-try-files-and-regex-location/213788/3 "2011-11-12T00:14:15Z")

</div>

Thanks this was the solution.  
Also thanks to Valentin.

BR  
Aleks

---

<div class="post-metadata">

**Author:** ![Aleksandar\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8edcca/32.png) [@Aleksandar\_L](https://www.ruby-forum.com/u/Aleksandar_L)\
**Post date:** [November 11, 2011, 2:18pm UTC](https://www.ruby-forum.com/t/q-about-try-files-and-regex-location/213788/4 "2011-11-11T14:18:50Z")

</div>

Hello!

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

> nginx: built by gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5)
> 
> ### 
> 
> ```
> }
> 
> ```
> 
> 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](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 D.
