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

前端之家收集整理的这篇文章主要介绍了如何仅使用nginx将特定文件添加到特定文件中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有图片,我想添加他们的标题为最大,我有个人资料的图片,可以更改和发布图片,我想添加标题只为后期图片,但不是个人资料图片,我不知道如何管理这个.谢谢,这是我的配置,

  1. this is the path of posts,/post/name-of-the-picture.jpg
  2. this is the path of users,/user/name-of-the-picture.jpg

我只想添加标题来发布路径

  1. location ~* \.(css|js|png|gif)${
  2. expires max;
  3. add_header Pragma public;
  4. add_header Cache-Control "public";
  5. }
最佳答案
目前我们有两个选择来解决这个问题:

选项1:

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

  1. location /post/ {
  2. post config stuff;
  3. .
  4. .
  5. .
  6. }
  7. location ~* ^/post/.*\.(css|js|png|gif)${
  8. post/files.(css|js|png|gif) config stuff;
  9. expires max;
  10. add_header Pragma public;
  11. add_header Cache-Control "public";
  12. }
  13. location /user/ {
  14. user folder config stuff;
  15. .
  16. .
  17. .
  18. }
  19. location ~* ^/user/.*\.(css|js|png|gif)${
  20. user/files.(css|js|png|gif) config stuff;
  21. .
  22. .
  23. .
  24. }

选项二:

Nested locations: Filtered by extension in the inner location blocks

  1. location /post/{
  2. ...
  3. location ~* \.(css|js|png|gif)${
  4. expires max;
  5. add_header Pragma public;
  6. add_header Cache-Control "public";
  7. }
  8. }
  9. location /user/{
  10. ...
  11. location ~* \.(css|js|png|gif)${
  12. ...
  13. }
  14. }

猜你在找的Nginx相关文章