Problems with rewrite on windows

Hello everyone!

I am experiencing a rather unsuspected problem with rewrites in nginx on
a Windows 2003 server.

I have a system running behind nginx, which generates HTML files and
places them
in folders.

In my config I have following:

if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}

As you all know, this is to produce clean urls, and this works well in
almost all situations.
Except when one enters an address using non-ascii characters (the site
is danish, so they are frequent.)

When I enter the url (ex) /mere/æv/ I get a 404
The corrosponding line in error.log is

2009/09/10 13:50:22 4020#3292: *2
“c:/webroot/WEBSITE/site/www/mere/æv/index.html” is not found (3: The
system cannot find the path specified), client: MYIPADDR, server:
WEBSITE, request: “GET /mere/%C3%A6v/ HTTP/1.1”, host: “WEBSITE”

And this is in access log :

MYIPADDR - - [10/Sep/2009:13:50:22 +0200] “GET /mere/%C3%A6v/ HTTP/1.1”
404 143 “-” “Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.2)
Gecko/20090729 Firefox/3.5.2”

First of all, the path and filename is correct.
The really weird thing is that when I put the index.html after the URL
in the browser (ie) /mere/æv/index.html it works fine!

See this line in access log :

MYIPADDR - - [10/Sep/2009:13:51:15 +0200] “GET /mere/%C3%A6v/index.html
HTTP/1.1” 304 0 “-” “Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US;
rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2”

Here is a request for a straight URL with only ASCII, works fine.

MYIPADDR - - [10/Sep/2009:13:53:50 +0200] “GET /mere/ HTTP/1.1” 304 0
“-” “Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.2)
Gecko/20090729 Firefox/3.5.2”

This setup works fine on a linux box and os x, but is giving me
headaches on windows :frowning:

Additional info :
The folder in the example is named “æv”, not “%C3%A6v” or the like. This
works on the other boxes and when appending index.html to the url.

Any help would be greatly appreciated, many thanks in advance

Halfdan Mouritzen

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,6256,6256#msg-6256

On Thu, Sep 10, 2009 at 08:12:55AM -0400, halfd wrote:

if (-f $request_filename/index.html) {
2009/09/10 13:50:22 4020#3292: *2 “c:/webroot/WEBSITE/site/www/mere/??v/index.html” is not found (3: The system cannot find the path specified), client: MYIPADDR, server: WEBSITE, request: “GET /mere/%C3%A6v/ HTTP/1.1”, host: “WEBSITE”
See this line in access log :

Additional info :
The folder in the example is named “??v”, not “%C3%A6v” or the like. This works on the other boxes and when appending index.html to the url.

Any help would be greatly appreciated, many thanks in advance

This is a bug in nginx/Windows.

 try_files  $uri/index.html

should work.

Hi Igor thanks for the reply and the idea,

however it is still not working.

Now I get this error :
2009/09/10 14:49:51 3388#2684: *87 rewrite or internal redirection
cycle while internal redirect to
“/mere/æv//index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html”,
client: IPADDR, server: SERVERNAME, request: “GET /mere/%C3%A6v/
HTTP/1.1”, host: “SERVERNAME”, referrer: “http://SERVERNAME/mere/

The setting I have in nginx.conf is as so :

location / {
root c:/webroot/detfri.dk/site/www/;
try_files $uri $uri/index.html;
}

At least now, there is a 500 server error. And it still works on ASCII
urls.

Thanks a million
Halfdan

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,6256,6268#msg-6268

BTW - This is nginx -V :

nginx version: nginx/0.7.61

configure arguments: --builddir=objs.msvc8 --crossbuild=win32
–with-debug --pre
fix= --conf-path=conf/nginx.conf --pid-path=logs/nginx.pid
–http-log-path=logs/
access.log --error-log-path=logs/error.log --sbin-path=nginx.exe
–http-client-b
ody-temp-path=temp/client_body_temp
–http-proxy-temp-path=temp/proxy_temp --htt
p-fastcgi-temp-path=temp/fastcgi_temp --with-cc-opt=-DFD_SETSIZE=1024
–with-pcr
e=objs.msvc8/lib/pcre-7.9 --with-openssl=objs.msvc8/lib/openssl-0.9.8k
–with-op
enssl-opt=enable-tlsext --with-zlib=objs.msvc8/lib/zlib-1.2.3
–with-select_modu
le --with-http_ssl_module --with-http_realip_module
–with-http_addition_module
–with-http_sub_module --with-http_dav_module
–with-http_stub_status_module --w
ith-http_flv_module --with-http_gzip_static_module
–with-http_random_index_modu
le --with-http_secure_link_module --with-mail --with-mail_ssl_module
–with-ipv6

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,6256,6261#msg-6261

On Thu, Sep 10, 2009 at 08:59:33AM -0400, halfd wrote:

 root   c:/webroot/detfri.dk/site/www/;
 try_files $uri $uri/index.html;

}

At least now, there is a 500 server error. And it still works on ASCII urls.

Probbaly, you should use:

location / {
root c:/webroot/detfri.dk/site/www/;
try_files $uri/index.html $uri;
}

Igor S. Wrote:

Probbaly, you should use:

location / {
root c:/webroot/detfri.dk/site/www/;
try_files $uri/index.html $uri;
}

Tried that, and unfortunately it does not work. Nginx gives me a 500 due
to too many internal redirects.
It still works then not containing ASCII chars, so thats seems to be
where the problem is.

I’ve just been experimenting with different setups of the config, but
nothing gives me the correct result :frowning:

thanks, Halfdan

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,6256,6281#msg-6281

On Thu, Sep 10, 2009 at 09:57:51AM -0400, halfd wrote:

It still works then not containing ASCII chars, so thats seems to be where the problem is.

I’ve just been experimenting with different setups of the config, but nothing gives me the correct result :frowning:

Could you show your current configuration with

if (-f $request_filename …

?

Igor S. Wrote:

Could you show your current configuration with

if (-f $request_filename …

?

location / {
root c:/webroot/detfri.dk/site/www/;
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
}

The new with try_files looks like this

location / {
root c:/webroot/detfri.dk/site/www/;
try_files $uri/index.html $uri;
}

halfdan

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,6256,6289#msg-6289

On Thu, Sep 10, 2009 at 10:26:46AM -0400, halfd wrote:

if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
}

The new with try_files looks like this

location / {
root c:/webroot/detfri.dk/site/www/;
try_files $uri/index.html $uri;
}

Well, then you need

location / {
root c:/webroot/detfri.dk/site/www/;
try_files $uri $uri/index.html =404;
}

Hi again everyone,

I’m still having great difficulties getting this to work.

(clean urls by having folders with index.html files in them generated by
backend)
As of now, nginx doesn´t find an index.html file in a folder, if the
foldername contains non ascii chars.

Igor said this was due to a bug in nginx on windows, which I can
confirm, since this setup works on linux and os x.

A sollution :

Well, then you need

location / {
root c:/webroot/SITE/site/www/;
try_files $uri $uri/index.html =404;
}

Unfortunately this does not work, but does give me an 404.

The thing is, there is a file at the path, but nginx is not finding it
due to a non-ascii character in the url.
Weird thing, because it works when accessing the file directly.

ie.

/something/ørne/index.html = works
/something/ørne/ = does not work

Also urls with only ascii chars work in both cases

/something/else/index.html = works
/something/else/ = works

This seems to be an error in nginx for windows, so maybe the solution is
to beg my client to install linux on their server instead :slight_smile:
unfortunately this seems further fetched than getting nginx to function.

Anybody got some insight?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,6256,7110#msg-7110

On Tue, Sep 15, 2009 at 10:10:03AM -0400, halfd wrote:

Weird thing, because it works when accessing the file directly.

This seems to be an error in nginx for windows, so maybe the solution is to beg my client to install linux on their server instead :slight_smile: … unfortunately this seems further fetched than getting nginx to function.

Anybody got some insight?

This bug will be fixed in 0.8.16.