# Alias regex use causing core dump as of nginx 1.7.1

**URL:** <https://www.ruby-forum.com/t/alias-regex-use-causing-core-dump-as-of-nginx-1-7-1/242786>\
**Category:** NGINX\
**Created:** [July 26, 2015, 4:26pm UTC](https://www.ruby-forum.com/t/alias-regex-use-causing-core-dump-as-of-nginx-1-7-1/242786 "2015-07-26T16:26:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [July 26, 2015, 4:26pm UTC](https://www.ruby-forum.com/t/alias-regex-use-causing-core-dump-as-of-nginx-1-7-1/242786/1 "2015-07-26T16:26:06Z")

</div>

Hi, after upgrading from the v1.6.3 to v1.8.0 stable branch an alias I  
used  
for Roundcubemail no longer works.  
I traced the issue back to a probable change made in nginx v1.7.1:  
“Bugfix: the “alias” directive used inside a location given by a regular  
expression worked incorrectly if the “if” or “limit\_except” directives  
were  
used.”

In version 1.6.3 and 1.7.0 the following works fine:  
## Roundcubemail for Remi repository  
location ~ ^/mail/(.+.php)$ {  
alias /usr/share/roundcubemail/$1;  
client\_max\_body\_size 5M;  
fastcgi\_pass \_php;  
}  
location ~ /mail {  
alias /usr/share/roundcubemail/;  
client\_max\_body\_size 5M;  
try\_files $uri $uri/ /index.php;  
}

But in v1.7.1 it causes nginx to core dump if I visit the url  
[Domain.com Login](http://domain.com/mail) and if I visit [Domain.com Login](http://domain.com/mail/) I get taken to the front  
page.

[notice] 26221#0: signal 17 (SIGCHLD) received  
[alert] 26221#0: worker process 26223 exited on signal 11 (core dumped)  
[notice] 26221#0: start worker process 26231  
[notice] 26221#0: signal 29 (SIGIO) received

Posted at Nginx Forum:

> **[Alias regex use causing core dump as of nginx 1.7.1](https://forum.nginx.org/read.php?2,260558,260558#msg-260558)**
>
> Hi, after upgrading from the v1.6.3 to v1.8.0 stable branch an alias I used for Roundcubemail no longer works. I traced the issue back to a probable change made in nginx v1.7.1: "Bugfix: the "alias" directive used inside a location...

---

<div class="post-metadata">

**Author:** ![Per\_Hansson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@Per\_Hansson](https://www.ruby-forum.com/u/Per_Hansson)\
**Post date:** [July 27, 2015, 7:47am UTC](https://www.ruby-forum.com/t/alias-regex-use-causing-core-dump-as-of-nginx-1-7-1/242786/2 "2015-07-27T07:47:53Z")

</div>

Hello!

On Sun, Jul 26, 2015 at 10:25:19AM -0400, Per Hansson wrote:

> ```
> alias /usr/share/roundcubemail/$1;
> 
> ```
> 
> [domain.com/mail](http://domain.com/mail) and if I visit [domain.com/mail/](http://domain.com/mail/) I get taken to the front  
> page.
> 
> [notice] 26221#0: signal 17 (SIGCHLD) received  
> [alert] 26221#0: worker process 26223 exited on signal 11 (core dumped)  
> [notice] 26221#0: start worker process 26231  
> [notice] 26221#0: signal 29 (SIGIO) received

Thanks, it was broken by this commit:

> **[hg.nginx.org is decommissioned](http://hg.nginx.org/nginx/rev/c985d90a8d1f)**

The patch below will fix the segfault. Note though, that the  
result will probably won’t work for you. Proper way to fix this  
would be to don’t use regex location for /mail, but use a prefix  
one instead, i.e.:

```
location /mail {
    alias /usr/share/roundcubemail/;
    try_files $uri $uri/ /index.php;
}

```

(Note: no “~”.)

The configuration with regex location previously worked by  
coincidence - in try\_files nginx used to do string comparison with  
regular expression specified, and this happened to produce  
sensible result in your case.

Patch:

# HG changeset patch

# User Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

# Date 1437975869 -10800

# Mon Jul 27 08:44:29 2015 +0300

# Node ID cb8f6e9d9943e2c8bd332443c0018a40353288fe

# Parent d34cda011a8ed968c5f2c4469ce43b7e7f0afda6

Fixed segfault with try\_files introduced by c985d90a8d1f.

If alias was used in a location given by a regular expression,  
nginx used to do wrong thing in try\_files if a location name (i.e.,  
regular expression) was an exact prefix of URI. The following  
configuration triggered a segmentation fault on a request to “/mail”:

```
location ~ /mail {
    alias /path/to/directory;
    try_files $uri =404;
}

```

Reported by Per Hansson.

diff --git a/src/http/ngx\_http\_core\_module.c  
b/src/http/ngx\_http\_core\_module.c  
— a/src/http/ngx\_http\_core\_module.c  
+++ b/src/http/ngx\_http\_core\_module.c  
@@ -1239,7 +1239,9 @@ ngx\_http\_core\_try\_files\_phase(ngx\_http\_r

```
         *e.pos = '\0';

```

- 

```
       if (alias && ngx_strncmp(name, clcf->name.data, alias) == 

```

1. {

- 

```
       if (alias && alias != NGX_MAX_SIZE_T_VALUE

```

- 

```
           && ngx_strncmp(name, clcf->name.data, alias) == 0)

```

- 

```
       {
           ngx_memmove(name, name + alias, len - alias);
           path.len -= alias;
       }

```

–  
Maxim D.

> **[nginx](http://nginx.org/)**

---

<div class="post-metadata">

**Author:** ![Per\_Hansson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@Per\_Hansson](https://www.ruby-forum.com/u/Per_Hansson)\
**Post date:** [July 27, 2015, 1:27pm UTC](https://www.ruby-forum.com/t/alias-regex-use-causing-core-dump-as-of-nginx-1-7-1/242786/3 "2015-07-27T13:27:17Z")

</div>

Thanks Maxim, you are correct about not making the /mail location a  
regex,  
it solves the problem.  
As for the core dump I compiled v1.9.3 with your patch and can confirm  
it no  
longer crashes with the original config.  
But as you suspected the config anyway does not work without removing  
the  
regex for the /mail location…  
Thanks for the quick fix!

Posted at Nginx Forum:

> **[Re: Alias regex use causing core dump as of nginx 1.7.1](https://forum.nginx.org/read.php?2,260558,260567#msg-260567)**
>
> Hi, after upgrading from the v1.6.3 to v1.8.0 stable branch an alias I used for Roundcubemail no longer works. I traced the issue back to a probable change made in nginx v1.7.1: "Bugfix: the "alias" directive used inside a location...
