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:, server: i.domain.com, request: "GET /favicon.ico HTTP/1.1", host: "i.domain.com"

server {
        listen; ## 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;
  • I forgot to mention that the nginx sits behinds a HAPROXY which runs on a different box on port 80 and forwards i.domain.com requests to the nginx – vivekv Dec 21 '12 at 5:52
  • What nginx version are you running? I couldn't reproduce this in 1.2.3. Also, what happens if you request /favicon.ico from nginx itself, not via haproxy? – sendmoreinfo Dec 27 '12 at 20:00
  • Also, does /index.html exist? – sendmoreinfo Dec 27 '12 at 20:07

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.


You did not create index.html file in /project directory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.