【问题标题】:LiipImagineBundle not working on production environmentLiipImagineBundle 在生产环境中不起作用
【发布时间】:2016-07-30 15:33:14
【问题描述】:

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

config.yml:

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:

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

树枝:

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

【问题讨论】:

  • 那么问题是缓存文件没有创建或者url没有生成?
  • @Florent 没有生成缓存文件。
  • 你清除了缓存? dev 和 prod 环境之间的问题来自 90% 的时间没有清除缓存! :)
  • @Florent 是的,当然。我开始认为这是 nginx 配置问题。我在某处读到 nginx 在 LiipImagineBundle 创建缓存文件之前做了一些重定向。

标签: symfony liipimaginebundle vichuploaderbundle


【解决方案1】:

我遇到了类似的问题,但在Symfony 4.2 上使用LiipImagineBundle 2.1。 就我而言,我用于缓存图像的 Nginx 规则覆盖了 LiipImagineBundle 的路由。

    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/ 添加了一个单独的位置:

    location ^~ /media/cache/resolve/ {
        try_files $uri /index.php$is_args$args;
    }

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-01
  • 1970-01-01
  • 2023-03-13
相关资源
最近更新 更多