Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I updated nginx recently to version 1.2.2 and the following entry seems to be broken; presumably a change in syntax between versions?

location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri /index.html;
        }

When I browser to http://www.mysite.com/a-non-existent-url I get redirected to the a "500 Internal Server Error" error page. The following log entry is made;

2012/08/13 09:20:29 [error] 18457#0: *60 rewrite or internal redirection cycle 
while internally redirecting to "/index.html", client: 10.0.14.1, server: 
mysite.com, request: "GET /a-non-existent-url HTTP/1.1", host: "www.mysite.com"

This used to work as expected, I can't find the correct syntax for this version. How should this be now?

UPDATE Full config as request;

server {

    root /usr/share/nginx/mysite.com/public_html;
    index index.php index.html index.htm;
    server_name mysite.com www.mysite.com;
    access_log  /usr/share/nginx/mysite.com/logs/access_log;
    error_log   /usr/share/nginx/mysite.com/logs/error_log;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to index.html
        try_files $uri $uri/ /index.html;
    }

    #Added for awstats
    location ^~ /awstats-icon {
            alias /usr/share/awstats/icon/;
            access_log off;
    }

    #Added for awstats
    location ^~ /awstatscss {
            alias /usr/share/doc/awstats/examples/css/;
            access_log off;
    }

    #Added for awstats
    location ^~ /awstatsclasses {
            alias /usr/share/doc/awstats/examples/classes/;                                 
            access_log off;
    }

    #Added for awstats
    # Configure /cgi-bin/scripts to go through php-fastcgi
    location ~ ^/cgi-bin/.*\.(cgi|pl|py|rb) {
            gzip off;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index cgi-bin.php;
            fastcgi_param SCRIPT_FILENAME    /etc/nginx/cgi-bin.php;
            fastcgi_param SCRIPT_NAME        /cgi-bin/cgi-bin.php;
            fastcgi_param X_SCRIPT_FILENAME  /usr/lib$fastcgi_script_name;
            fastcgi_param X_SCRIPT_NAME      $fastcgi_script_name;
            fastcgi_param QUERY_STRING       $query_string;
            fastcgi_param REQUEST_METHOD     $request_method;
            fastcgi_param CONTENT_TYPE       $content_type;
            fastcgi_param CONTENT_LENGTH     $content_length;
            fastcgi_param GATEWAY_INTERFACE  CGI/1.1;
            fastcgi_param SERVER_SOFTWARE    nginx;
            fastcgi_param REQUEST_URI        $request_uri;
            fastcgi_param DOCUMENT_URI       $document_uri;
            fastcgi_param DOCUMENT_ROOT      $document_root;
            fastcgi_param SERVER_PROTOCOL    $server_protocol;
            fastcgi_param REMOTE_ADDR        $remote_addr;
            fastcgi_param REMOTE_PORT        $remote_port;
            fastcgi_param SERVER_ADDR        $server_addr;
            fastcgi_param SERVER_PORT        $server_port;
            fastcgi_param SERVER_NAME        $server_name;
            fastcgi_param REMOTE_USER        $remote_user;
    }

    #Make sure all PHP is process by php-fpm
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    #rTorrent/wTorrent needs this
    #To loop back to the xml rpc service
        location /RPC2 {
                scgi_pass   127.0.0.1:5000;
                include     scgi_params;
                scgi_param    SCRIPT_NAME  /RPC2;
        }

}

2nd UPDATE

A debug log has beed posted here (http://pastebin.com/raw.php?i=PtLwvQhW). Its quite long so I have done this to avoid spamming this post.

share|improve this question
    
Show your full config. –  quanta Aug 13 '12 at 8:29
1  
Append debug to the end of error_log line, try again and post the error log here. –  quanta Aug 13 '12 at 9:01
    
I have added a link to a paste bin in my post; pastebin.com/raw.php?i=PtLwvQhW –  jwbensley Aug 13 '12 at 9:58
    
ls -l /usr/share/nginx/mysite.com/public_html/index.html? –  quanta Aug 13 '12 at 10:21

1 Answer 1

up vote 5 down vote accepted

modify the try_files line to

try_files $uri $uri/ /index.html =404;

Ref: http://wiki.nginx.org/HttpCoreModule#try_files

share|improve this answer
1  
OK a couple of stupid points here on my part. Firstly index.html doesn't exists and that should be index.php, which it was originally, I have an old copy of the config showing that (just running a diff has pointed this out to me). Not sure how that changed?! Secondly, pointing to /index.php actually caused my browser to download the raw php code which is a little dangerous, but point to / works just great. So the line is now try_files $uri $uri/ / =404; Thanks a lot :D –  jwbensley Aug 13 '12 at 10:22
    
Thanks very much. I'd removed the /index.html from mine without knowing that try_files causes an internal redirect to the last item in the list if none match. I left the line as try_files $uri $uri/ =404; which works well in my case. –  Drew Noakes Jan 12 '13 at 21:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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