Nginx 0.8.54: Index files bug?

Just noticed an issue with my 0.8.54 installation.

  1. URL = www.site.com, Result = 500 error
server {
...
  index index.html;
  location / {
    try_files $uri $uri/;
  }
}
  1. URL = www.site.com, Result = 500 error
server {
...
  location / {
  index index.html;
    try_files $uri $uri/;
  }
}
  1. URL = www.site.com, Result = 200 OK
server {
...
  location / {
    try_files $uri $uri/index.html;
  }
}
  1. URL = www.site.com/index.html, Result = 200 OK
server {
...
  location / {
    try_files $uri $uri/;
  }
}

It seems that the index module does not work with the try_files
directive. Would have expected the trying of ‘$uri/’ to include the
defined index but it doesn’t do so.

Anyone else notice this?

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

On Fri, Feb 11, 2011 at 06:45:25AM -0500, Dayo wrote:

}
}
[/code]

It seems that the index module does not work with the try_files
directive. Would have expected the trying of ‘$uri/’ to include the
defined index but it doesn’t do so.

Anyone else notice this?

What is in error_log ?


Igor S.
http://sysoev.ru/en/

Igor S. Wrote:

It seems that the index module does not work
with the try_files
directive. Would have expected the trying of
‘$uri/’ to include the
defined index but it doesn’t do so.

Anyone else notice this?

What is in error_log ?

Nothing.

Here is my Nginx -V

[[email protected] ~]# nginx -V
nginx version: nginx/0.8.54
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
TLS SNI support disabled
configure arguments:
–user=nginx
–group=nginx
–prefix=/usr/share/nginx
–sbin-path=/usr/sbin/nginx
–conf-path=/etc/nginx/nginx.conf
–error-log-path=/var/log/nginx/error.log
–http-log-path=/var/log/nginx/access.log
–http-client-body-temp-path=/var/lib/nginx/tmp/client_body
–http-proxy-temp-path=/var/lib/nginx/tmp/proxy
–http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi
–pid-path=/var/run/nginx.pid
–lock-path=/var/lock/subsys/nginx
–with-http_ssl_module
–with-http_realip_module
–with-http_stub_status_module
–with-http_perl_module
–with-mail
–with-mail_ssl_module
–with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions
-fstack-protector
–param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic
-fasynchronous-unwind-tables’
–add-module=/usr/src/redhat/BUILD/nginx-0.8.54/nginx-upstream-fair
–add-module=/usr/src/redhat/BUILD/nginx-0.8.54/ngx_cache_purge-1.2
–add-module=/usr/src/redhat/BUILD/nginx-0.8.54/ngx-headers-more
–add-module=/usr/src/redhat/BUILD/nginx-0.8.54/ngx-devel-kit
–add-module=/usr/src/redhat/BUILD/nginx-0.8.54/ngx-echo-module
–add-module=/usr/src/redhat/BUILD/nginx-0.8.54/ngx-lua-module
–without-http_autoindex_module
–without-http_empty_gif_module
–without-http_memcached_module
–without-http_scgi_module
–without-http_split_clients_module
–without-http_ssi_module
–without-http_upstream_ip_hash_module
–without-http_uwsgi_module

As shown, I do have a few 3rd party modules and I disabled a few
standard ones I don’t use.

I did notice a while back that stuff did not work when the perl module
was disabled and perhaps disabling the autoindex module is affecting
this.

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

Igor S. Wrote:

Standard nginx modules logs a reason of 500 error.

I have done a plain vanilla build of v0.8.54 without any third party
modules and I both still get the same results and do not have anything
in the error log.

Not sure why nothing is getting logged but at least I know this is not
down to the third party modules.

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

On Fri, Feb 11, 2011 at 08:33:44AM -0500, Dayo wrote:

Igor S. Wrote:

Standard nginx modules logs a reason of 500 error.

I have done a plain vanilla build of v0.8.54 without any third party
modules and I both still get the same results and do not have anything
in the error log.

Not sure why nothing is getting logged but at least I know this is not
down to the third party modules.

Could you create a debug log ?
http://nginx.org/en/docs/debugging_log.html


Igor S.
http://sysoev.ru/en/

server {
...
  index index.html;
  location / {
                error_log  /path/to/log  debug;
    try_files $uri $uri/;
  }
}

…gives me an empty error log file.

I don’t think my isp has cached the response because as soon as I change
to …

server {
...
  index index.html;
  location / {
    try_files $uri $uri/ @proxy;
  }
}

It starts working … using the apache index files setup.

Wonder whether anyone else can reproduce

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

On Fri, Feb 11, 2011 at 07:16:22AM -0500, Dayo wrote:

What is in error_log ?
–user=nginx
–lock-path=/var/lock/subsys/nginx
–add-module=/usr/src/redhat/BUILD/nginx-0.8.54/nginx-upstream-fair
–without-http_ssi_module
–without-http_upstream_ip_hash_module
–without-http_uwsgi_module

As shown, I do have a few 3rd party modules and I disabled a few
standard ones I don’t use.

I did notice a while back that stuff did not work when the perl module
was disabled and perhaps disabling the autoindex module is affecting
this.

Standard nginx modules logs a reason of 500 error.


Igor S.
http://sysoev.ru/en/

Narrowed the issue down to the try_files directive.

These configurations work:

  1. URL = www.site.com, Result = 200 OK
server {
...
  index index.html;
  location / {
    #try_files $uri $uri/;
  }
}
  1. URL = www.site.com, Result = 200 OK
server {
...
  location / {
          index index.html;
    #try_files $uri $uri/;
  }
}

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

Hello!

On Fri, Feb 11, 2011 at 09:13:06AM -0500, Dayo wrote:

…gives me an empty error log file.

It should log something like “rewrite or internal redirection
cycle” at “error” level. Obviously enough your config creates an
infinite loop on processing “/” as you set try_files’s fallback to
effectively the same uri, just with extra “/” added.

No idea why you have no logs - most likely you did something wrong
(e.g. nginx has no access rights to write the file in question and
config wasn’t actually loaded due to this error, but you’ve
overlooked related messages in global error_log).

}
[/code]

It starts working … using the apache index files setup.

This one should use index.html as an index (and fallback to @proxy
if no index.html found or there is no directory at all).

Maxim D.

On Fri, Feb 11, 2011 at 10:43:19AM -0500, Dayo wrote:

try_files’s fallback to
effectively the same uri, just with extra “/”
added.

Did you see my previous post?
When I comment out the try files directive, the index works.

As Maxim already said you should see in the log

[error] … rewrite or internal redirection cycle while
internal redirect to “/”


Igor S.
http://sysoev.ru/en/

Hi Maxim!

Maxim D. Wrote:

No idea why you have no logs - most likely you did
something wrong
(e.g. nginx has no access rights to write the file
in question and
config wasn’t actually loaded due to this error,
but you’ve
overlooked related messages in global error_log).

The error log file does log other errors.

This one should use index.html as an index (and
fallback to @proxy
if no index.html found or there is no directory at
all).
Correct. It only works because it is falling back to apache.

Did you see my previous post?
When I comment out the try files directive, the index works.

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

Hi Maxim!

Maxim D. Wrote:

is an infinite loop. It is expected to generate
500 for
directories. Under no conditions it will allow
index to work.

OK. That is clear enough.

My normal setup is
location / {
try_files $uri $uri/ @proxy;
}
I just ran the ‘try_files $uri $uri/;’ as a test to try to see whether
the file gets served by Nginx or by the backend if it is the index.html
being called.

I see now from your explanation that the test would always fail.

Thanks

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

Hello!

On Fri, Feb 11, 2011 at 10:43:19AM -0500, Dayo wrote:

try_files’s fallback to

The error log file does log other errors.

This is fine, but doesn’t explain why don’t see the one in
question. It’s hard to say anything without seeing the full
config.

This one should use index.html as an index (and
fallback to @proxy
if no index.html found or there is no directory at
all).
Correct. It only works because it is falling back to apache.

Did you see my previous post?
When I comment out the try files directive, the index works.

Again:

location / {
    try_files $uri $uri/;
}

is an infinite loop. It is expected to generate 500 for
directories. Under no conditions it will allow index to work.

This is what you wrote in your config: check if file (not
directory) “$uri” exists, if not - do internal redirect to
“$uri/”.

If you want nginx to return 404 if no file or directory exists -
use

location / {
    try_files $uri $uri/ =404;
}

Or, better, just don’t use try_files - it’s not needed here.
Index and static modules will generate 404 as appropriate.

Maxim D.

Hi Maxim! Hi Igor!

Maxim D. Wrote:

The error log file does log other errors.

This is fine, but doesn’t explain why don’t see
the one in
question. It’s hard to say anything without
seeing the full
config.

I went back to look over my config in detail and noticed I was
generating two separate error logs. The error was indeed being logged
by the debug as stated.

Thanks again for your help.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs