首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >LiipImagineBundle在生产环境中不起作用

LiipImagineBundle在生产环境中不起作用
EN

Stack Overflow用户
提问于 2016-07-30 23:33:14
回答 1查看 684关注 0票数 0

我在Symfony 3.1.3上结合使用LiipImagineBundle 1.6.0VichUploaderBundle 1.2.0,在dev上一切正常,但在prod上,他不保存缓存文件。图像保存正确,所以不存在VichUploaderBundle的问题。

config.yml:

代码语言:javascript
复制
vich_uploader:
    db_driver: orm # or mongodb or propel or phpcr
    mappings:
            pop_image:
                uri_prefix:         /images/pops
                upload_destination: %kernel.root_dir%/../web/images/pops
            ad_image:
                uri_prefix:         /images/ads
                upload_destination: %kernel.root_dir%/../web/images/ads
liip_imagine:
    resolvers:
       default:
          web_path: ~

    filter_sets:
        cache: ~
        square:
            quality: 75
            filters:
                thumbnail: { size: [400, 400], mode: outbound }

routing.yml:

代码语言:javascript
复制
_liip_imagine:
    resource: "@LiipImagineBundle/Resources/config/routing.xml"

小枝:

代码语言:javascript
复制
...
<div class="image">
   <img src="{{ vich_uploader_asset(pop,'imageFile')|imagine_filter('square') }}" alt="{{ pop.question }}" width="100%" class="grayscale" />
   <span class="image-question">{{ pop.question }}</span>
</div>
...
EN

回答 1

Stack Overflow用户

发布于 2019-09-30 21:11:25

我也遇到过类似的问题,不过是Symfony 4.2上的LiipImagineBundle 2.1。在我的例子中,我用来缓存图像的Nginx规则覆盖了LiipImagineBundle的路由。

代码语言:javascript
复制
    location / {
        # try to serve file directly, fallback to index.php
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;

        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/index.php/some-path
        # Remove the internal directive to allow URIs like this
        internal;
    }

    # Cache images.
    location ~* \.(?:ico|css|gif|jpe?g|png)$ {
        expires 30d;
        add_header Vary Accept-Encoding;
        access_log off;
    }

因此,我为/media/cache/resolve/添加了一个单独的位置

代码语言:javascript
复制
    location ^~ /media/cache/resolve/ {
        try_files $uri /index.php$is_args$args;
    }

^~前缀告诉Nginx停止寻找其他位置(更多关于Nginx location priority的信息)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38675616

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档