0

I use LiipImagineBundle 1.6.0 on Symfony 3.1.3 combined with VichUploaderBundle 1.2.0 and everything goes fine on dev but on prod he doesn't save cached files. Images are saving correctly so there is rather not a problem of 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"

twig:

...
<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>
...
Starspire
  • 272
  • 3
  • 15

1 Answers1

0

I'm faced with a similar problem but with LiipImagineBundle 2.1 on Symfony 4.2. In my case, Nginx rule that I used for caching images overrides the route of 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;
    }

So, I've added a separate location for /media/cache/resolve/:

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

The ^~ prefix tells Nginx to stop looking for other locations (more about Nginx location priority).

vely
  • 101
  • 4
  • 1
    I've added the new rule at the beginning then at the end of the config : the problem remains ! I'm using Liip2.3/Sym4.4 Here is the entire nginx config file : https://www.writeurl.com/text/uquirzbmy51zsfyu4zi9/bknz0bvihor2l3pffznt – Sami Nov 06 '20 at 15:23
  • @Sami, I think that `if` inside your `location /` is blocking rule for `/media/cache/resolve/`. – vely Nov 22 '20 at 20:04