1

サイトでは、ルートではなくディレクトリにfavicon.ico保持されます。/images/そこを見るように言うにはどうすればいいnginxですか?

試してみました-正しく見えますが機能しません:

location = /favicon.ico$ { rewrite /(.*) /images/$1 last; }

戻り値404 Not Found

ファイルがあります: リクエストhttp://www.example.com/images/favicon.icoは成功しました

4

2 に答える 2

2

これも書き換えで解決できます。try_files(ディレクティブを使用しているため、書き換えを使用して解決する必要がありました。)

これが私の設定です:

# Long cache times for static content
location ~ /_/static/(.+)$  {
    # hold the last five versions of our static content
    try_files
        /_/static_477526f-master/$1
        /_/static_05c8613-release/$1
        /_/static_05c8613-master/$1
        /_/static_db26497-release/$1
        /_/static_db26497-master/$1;
    expires  365d;
    add_header Cache-Control public;
    add_header Access-Control-Allow-Origin *;
}

location = /favicon.ico {
    rewrite . /_/static/favicon.ico;
    expires  14d;
    add_header Cache-Control public;
}

正規表現は.何でも一致し、2 番目のエントリは URL を書き換えます。これはファビコン固有の場所であるため、正規表現のキャプチャと$1.

于 2015-09-19T05:39:44.400 に答える