如何仅使用nginx将特定文件添加到特定文件中

前端之家收集整理的这篇文章主要介绍了如何仅使用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";
}
最佳答案
目前我们有两个选择来解决这个问题:

选项1:

Duplicated locations: Nginx looks for the best match. (a little better performance)

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

选项二:

Nested locations: Filtered by extension in the inner location blocks

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)${
        ...

    }
}

猜你在找的Nginx相关文章