【问题标题】:Liipimagine Bundle - Images not cachedLiipimagine Bundle - 未缓存的图像
【发布时间】:2019-01-24 09:39:33
【问题描述】:

我收到了一个项目,我正尝试在 Docker 和 NGINX 环境中启动它。但似乎我对 LiipImagine 有一个错误。该项目使用 Symfony 4 和 LIIPImagine 版本 2.0.x-dev。

页面应显示缓存中的图像,例如图像 URL: https://localhost:8443/media/cache/live_feed_message/images/live_feed_message/5c486df1a78fe_lama-750389_960_720.jpg

目录存在且有权限:

drwxr-xr-x 2 1000 1000 4069 Jan 23 13:35 live_feed_message

所有图片都存储在 public/images/live_feed_mesage/ 中,而在 public/media/cache/live_feed_message/images/live_feed_message 中对应的图片不存在。

我发现如果我使用来自 LiipImagine 的命令: php app/console liip:imagine:cache:resolve relative/path/to/image1.jpg

它给出了这个结果:

http://localhost/media/cache/quizz_thumbnail/images/live_feed_message/name_file.jpg
http://localhost/media/cache/quizz_sponsors_icon/images/live_feed_message/name_file.jpg
http://localhost/media/cache/live_feed_message/images/live_feed_message/name_file.jpg

然后对应的图片存在缓存中(public/media/cache/live_feed_message/images/live_feed_message)并且图片在页面上正确显示...

在开发控制台的网络选项卡中,我检查了来自 HTTP 请求的响应。我得到了 Symfony 的回复:

Unable to write to the "/srv/api/public/media/cache/live_feed_message/images/live_feed_message" directory.

有人知道可能是什么问题吗?

2天后我无法解决此问题,感谢您的帮助!

PS:我从捆绑包中覆盖了 routing.yaml 中的路由。 在路径中有 /resolve,我用它覆盖了(实际上我从 liip_imagine_filter 路径中删除了 /resolve):

_liip_imagine:
    resource: "@LiipImagineBundle/Resources/config/routing.yaml"


liip_imagine_filter:
    path:  /media/cache/{filter}/{path}
    defaults:
        _controller: '%liip_imagine.controller.filter_action%'
    methods:
        - GET
    requirements:
        filter: '[A-z0-9_-]*'
        path: .+

【问题讨论】:

    标签: symfony ubuntu caching rights liipimaginebundle


    【解决方案1】:

    您也许应该尝试对chmod -R 777 public/images 更加宽容。在本地这不是什么大问题,在生产中您应该微调您的权限。这可能会清除您的错误,您可以继续编码。

    实际的生产许可是 755 IIRC。

    【讨论】:

    • 我在捆绑包的配置中搜索了一个问题,但最后我使用了 chmod -R 777 但不是在公共/图像上。我在公共/媒体/缓存文件夹中使用它。因为它试图写在那里而不是在公共/图像中。我不知道这是否是最佳做法,但它确实有效......
    • 是的,缓存在 /cache 但上传的图像在 /images。图像过滤器不与源存储在同一目录中。我认为将上传的内容与生成的内容分开是很好的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-16
    • 2012-05-26
    • 1970-01-01
    • 2013-08-28
    • 2016-03-17
    • 2015-10-28
    • 2014-08-23
    相关资源
    最近更新 更多