2013-06-05 28 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

謝謝,沒不知道你可以嵌套'位置'集團! –

相關問題