2013-06-05 8 views
11

写真があり、ヘッダーを最大に追加したいのですが、変更可能なプロフィール写真があり、写真を投稿できます。私はこれをどのように管理できるのか分かりません。ありがとう、これは私の設定で、nginxで特定のファイルのみにヘッダーを追加するには

this is the path of posts, /post/name-of-the-picture.jpg 

this is the path of users, /user/name-of-the-picture.jpg 

私は唯一のパス

location ~* \.(css|js|png|gif)$ { 
    expires max; 
    add_header Pragma public; 
    add_header Cache-Control "public"; 
} 

答えて

19

を投稿するヘッダを追加したい現在、我々はこれを解決する二つのオプションあります

オプション1:

重複した場所:NGINXが最もよく一致するものを探します。 (少しより良い性能)

location /post/ { 
    post config stuff; 
    . 
    . 
    . 
}  
location ~* ^/post/.*\.(css|js|png|gif)$ { 
    post/files.(css|js|png|gif) config stuff; 
    expires max; 
    add_header Pragma public; 
    add_header Cache-Control "public"; 
} 
location /user/ { 
    user folder config stuff; 
    . 
    . 
    . 
}  
location ~* ^/user/.*\.(css|js|png|gif)$ { 
    user/files.(css|js|png|gif) config stuff; 
    . 
    . 
    . 
} 

オプション2:

ネスト位置

location /post/{ 
    ... 

    location ~* \.(css|js|png|gif)$ { 
     expires max; 
     add_header Pragma public; 
     add_header Cache-Control "public"; 
    } 
} 
location /user/{ 
    ... 

    location ~* \.(css|js|png|gif)$ { 
     ... 

    } 
} 
+1

おかげ内側位置ブロックに拡張することによって、濾過のdidnあなたが 'location'ブロックを入れ子にすることができるのを知っている! –

関連する問題