NGINX : internal redirection cycle : help needed on configuration

configurationnginxUbuntu

I am trying to setup a very simple nginx config to serve static content. Here is my configuration setting. I get HTTP 500 whenever I try to access a non-existant file instead of a 404. Please let me know what am I doing wrong?

2012/12/21 11:15:14 [error] 1906#0: *41 rewrite or internal
redirection cycle while internally redirecting to "/index.html",
client: 127.0.0.1, server: i.domain.com, request: "GET /favicon.ico
HTTP/1.1", host: "i.domain.com"

server {
        listen   127.0.0.1:81; ## listen for ipv4; this line is default and implied
        root /project/;
        index index.html index.htm;
    location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
    access_log      off;
    log_not_found   off;
    expires         360d;
    }
        server_name i.domain.com;
        location / {
                try_files $uri $uri/ /index.html;
        }
        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/www;
        }
}

Best Answer

It appears you have 2 problems.

  1. You do not have an /index.html file
  2. You do not have a /404.html file

When a request is made, it goes through the try files process. At the end, it realizes that index.html does not exist and proceeds to return 404. To complete that task, it must now fetch 404.html and the request starts over. It checks $url (where $url is defined as "404.html"), then $url/, then index.html again and enters the infinite loop.

As you entered the inf loop, it's an internal error. Thus, fittingly error 500 is served.