Nginx 1.2.2:try_filesを動作させる方法は?


11

最近nginxをバージョン1.2.2に更新しましたが、次のエントリが壊れているようです。おそらくバージョン間の構文の変更?

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

Iブラウザときhttp://www.mysite.com/a-non-existent-urlは、私が「500内部サーバーエラー」エラーページにリダイレクトされます。次のログエントリが作成されます。

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"

これは予想どおりに機能していましたが、このバージョンの正しい構文が見つかりません。これは今どうあるべきでしょうか?

要求として完全な構成を更新します。

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;
        }

}

2回目の更新

デバッグログがここに投稿されています(http://pastebin.com/raw.php?i=PtLwvQhW)。非常に長いので、この投稿をスパムしないようにこれを行いました。


完全な設定を表示します。
量子

1
debug行末に追加しerror_log、もう一度試して、エラーログをここに投稿してください。
クォンタ

投稿に貼り付けビンへのリンクを追加しました。pastebin.com/raw.php?i=PtLwvQhW
jwbensley

ls -l /usr/share/nginx/mysite.com/public_html/index.html
クォンタ

回答:


12

try_files行を次のように変更します。

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

参照:https : //nginx.org/en/docs/http/ngx_http_core_module.html#try_files


1
ここで、私の愚かな点をいくつか説明します。まず、index.htmlは存在せず、index.phpである必要があります。これは元々ありましたが、それを示す設定の古いコピーがあります(diffを実行するだけでこれが指摘されています)。それがどのように変わったのか分かりませんか?!第二に、/ index.phpを指すと、実際にはブラウザーが生のphpコードをダウンロードするようになりますが、これは少し危険ですが、/を指すとうまく機能します。だから、行は今、try_files $uri $uri/ / =404;ありがとうございました:D
jwbensley

2
どうもありがとう。一致するものがない場合、リストの最後の項目への内部リダイレクト/index.htmltry_files発生することを知らずに、鉱山から削除しました。try_files $uri $uri/ =404;私の場合はうまくいくように行を残しました。
ドリューノアケス
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.