# Nginx's bug(alias and $request\_uri to conflict)

**URL:** <https://www.ruby-forum.com/t/nginxs-bug-alias-and-request-uri-to-conflict/196298>\
**Category:** NGINX\
**Created:** [October 11, 2010, 4:48am UTC](https://www.ruby-forum.com/t/nginxs-bug-alias-and-request-uri-to-conflict/196298 "2010-10-11T04:48:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![monad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@monad](https://www.ruby-forum.com/u/monad)\
**Post date:** [October 11, 2010, 4:48am UTC](https://www.ruby-forum.com/t/nginxs-bug-alias-and-request-uri-to-conflict/196298/1 "2010-10-11T04:48:34Z")

</div>

thanks!

my nginx version is 0.8.52, index.html in  
/home/my\_name/tools/nginx/html/  
, this is my nginx config:

worker\_processes 1;

error\_log logs/error.log debug;  
events {  
worker\_connections 1024;  
}  
http {  
include mime.types;  
default\_type application/octet-stream;  
expires 1y;  
sendfile on;  
server {  
listen 8080;  
server\_name localhost;  
location ~\* ^/html/(.+.html)$ {  
alias /home/my\_name/tools/nginx/html/$1;  
if ($request\_uri ~ .(html|htm|shtml)$) {  
expires 1h;  
}  
}  
error\_page 500 502 503 504 /50x.html;  
location = /50x.html {  
root html;  
}  
}  
}

and then exec curl -I 127.0.0.1:8080/html/index.html:

HTTP/1.1 404 Not Found  
Server: nginx/0.8.52  
Date: Mon, 11 Oct 2010 02:24:25 GMT  
Content-Type: text/html  
Content-Length: 169  
Connection: keep-alive

and this is error log:

2010/10/11 10:24:25 [debug] 8604#0: \*1 http request line: “GET  
/html/index.html HTTP/1.1”  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http uri: “/html/index.html”  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http args: “”  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http exten: “html”  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http process request header line  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http header: “User-Agent:  
curl/7.21.1  
(i686-pc-linux-gnu) libcurl/7.21.1 OpenSSL/1.0.0a zlib/1.2.5”  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http header: “Host:  
127.0.0.1:8080”  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http header: “Accept: _/_”  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http header done  
2010/10/11 10:24:25 [debug] 8604#0: \*1 event timer del: 3: 2568703927  
2010/10/11 10:24:25 [debug] 8604#0: \*1 rewrite phase: 0  
2010/10/11 10:24:25 [debug] 8604#0: \*1 test location: “/50x.html”  
2010/10/11 10:24:25 [debug] 8604#0: \*1 test location: ~  
“^/html/(.+.html)$”  
2010/10/11 10:24:25 [debug] 8604#0: \*1 using configuration  
“^/html/(.+.html)$”  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http cl:-1 max:1048576  
2010/10/11 10:24:25 [debug] 8604#0: \*1 rewrite phase: 2  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http script var  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http script var:  
“/html/index.html”  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http script regex:  
“.(html|htm|shtml)$”  
2010/10/11 10:24:25 [notice] 8604#0: \*1 “.(html|htm|shtml)$” matches  
“/html/index.html”, client: 127.0.0.1, server: localhost, request: “GET  
/html/index.html HTTP/1.1”, host: “127.0.0.1:8080”  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http script if  
2010/10/11 10:24:25 [debug] 8604#0: \*1 post rewrite phase: 3  
2010/10/11 10:24:25 [debug] 8604#0: \*1 generic phase: 4  
2010/10/11 10:24:25 [debug] 8604#0: \*1 generic phase: 5  
2010/10/11 10:24:25 [debug] 8604#0: \*1 access phase: 6  
2010/10/11 10:24:25 [debug] 8604#0: \*1 access phase: 7  
2010/10/11 10:24:25 [debug] 8604#0: \*1 post access phase: 8  
2010/10/11 10:24:25 [debug] 8604#0: \*1 content phase: 9  
2010/10/11 10:24:25 [debug] 8604#0: \*1 content phase: 10  
2010/10/11 10:24:25 [debug] 8604#0: \*1 content phase: 11  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http script copy:  
“/home/my\_name/tools/nginx/html/”  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http script capture: “html”  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http filename:  
“/home/my\_name/tools/nginx/html/htmlTTP/1.1  
User-Agent”  
2010/10/11 10:24:25 [debug] 8604#0: \*1 add cleanup: 09C64B40  
2010/10/11 10:24:25 [error] 8604#0: \*1 open()  
“/home/my\_name/tools/nginx/html/htm” failed (2: No such file or  
directory),  
client: 127.0.0.1, server: localhost, request: “GET /html/index.html  
HTTP/1.1”, host: “127.0.0.1:8080”  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http finalize request: 404,  
“/html/index.html?” a:1, c:1  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http special response: 404,  
“/html/index.html?”  
2010/10/11 10:24:25 [debug] 8604#0: \*1 http set discard body  
2010/10/11 10:24:25 [debug] 8604#0: \*1 HTTP/1.1 404 Not Found

and i remove this line in nginx config :

if ($request\_uri ~ .(html|htm|shtml)$) {  
expires 1h;  
}

and exec curl -I 127.0.0.1:8080/html/index.html:

HTTP/1.1 200 OK  
Server: nginx/0.8.52  
Date: Mon, 11 Oct 2010 02:26:33 GMT  
Content-Type: text/html  
Content-Length: 158  
Last-Modified: Sat, 05 Jun 2010 15:20:23 GMT  
Connection: keep-alive  
Expires: Tue, 11 Oct 2011 02:26:33 GMT  
Cache-Control: max-age=31536000  
Accept-Ranges: bytes

–  
åšè§‚çº¦å–

è±†ç“£:www.douban.com/people/mustang/

blog: www.pagefault.info

twitter: [www.twitter.com/minibobo](http://www.twitter.com/minibobo)

---

<div class="post-metadata">

**Author:** ![monad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@monad](https://www.ruby-forum.com/u/monad)\
**Post date:** [October 11, 2010, 7:07am UTC](https://www.ruby-forum.com/t/nginxs-bug-alias-and-request-uri-to-conflict/196298/2 "2010-10-11T07:07:48Z")

</div>

On Mon, Oct 11, 2010 at 10:46:28AM +0800, Simon L. wrote:

> }  
> if ($request\_uri ~ .(html|htm|shtml)$) {  
> expires 1h;  
> }  
> }  
> error\_page 500 502 503 504 /50x.html;  
> location = /50x.html {  
> root html;  
> }  
> }  
> }

1. [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/IfIsEvil)

2. location ~\* ^/html/(.+.html)$ {  
alias /home/my\_name/tools/nginx/html/$1;

3. …|shtml)$ is not matched by .html)$

4. regex is usele here, so

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![monad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@monad](https://www.ruby-forum.com/u/monad)\
**Post date:** [October 11, 2010, 7:58am UTC](https://www.ruby-forum.com/t/nginxs-bug-alias-and-request-uri-to-conflict/196298/3 "2010-10-11T07:58:42Z")

</div>

thank you!

On Mon, Oct 11, 2010 at 1:06 PM, Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > events {  
> > location ~\* ^/html/(.+.html)$ {  
> > }
> 
> –  
> Igor S.  
> [Igor Sysoev](http://sysoev.ru/en/)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
åšè§‚çº¦å–

è±†ç“£:www.douban.com/people/mustang/

blog: www.pagefault.info

twitter: [Minibobo (@minibobo) / X](http://www.twitter.com/minibobo)

---

<div class="post-metadata">

**Author:** ![monad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@monad](https://www.ruby-forum.com/u/monad)\
**Post date:** [October 11, 2010, 9:31am UTC](https://www.ruby-forum.com/t/nginxs-bug-alias-and-request-uri-to-conflict/196298/4 "2010-10-11T09:31:11Z")

</div>

Hello!

On Mon, Oct 11, 2010 at 10:46:28AM +0800, Simon L. wrote:

> }  
> if ($request\_uri ~ .(html|htm|shtml)$) {  
> expires 1h;  
> }

This is known issue with “if”. Avoid using “if”, use two separate  
locations instead.

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

Maxim D.
