2

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;
        }
}
3
  • 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, 2012 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? Dec 27, 2012 at 20:00
  • Also, does /index.html exist? Dec 27, 2012 at 20:07

2 Answers 2

0
+50

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.

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .