带有LiipImagineBundle的Symfony 3.2无法创建文件夹媒体/缓存

时间:2017-08-16 13:17:31

标签: php symfony nginx symfony-3.2 liipimaginebundle

我在制作时使用Symfony 3.2和LiipImagineBundle 1.8.0以及Nginx和php7 fpm。在desenv中,webserver是php内置服务器。在desenv工作正常,缓存目录在web文件夹中创建,但在生产中没有,Symfony返回404图像。知道那可能是什么吗?这是我的配置:

Nginx的

location / {
    try_files $uri @rewriteapp;
}

location @rewriteapp {
    rewrite ^(.*)$ /app.php/$1 last;
}

location ~ ^/app\.php(/|$) {

    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    fastcgi_param DOCUMENT_ROOT $realpath_root;
    internal;
}

location ~ \.(png|jpeg|jpg|gif)$ {
    if (-f $request_filename) {
        expires 18h;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        access_log off;
    }

    try_files $uri @rewriteapp;
}

Symfony配置

liip_imagine:
    resolvers:
        default:
            web_path:
                web_root: "%kernel.root_dir%/../web"
                cache_prefix: "media/cache"


    filter_sets:
        cache: ~

        slide:
            quality: 80
            filters:
                thumbnail: { size: [364, 244]}
                watermark:
                    image: Resources/data/logo.png
                    size: 0.2
                    position: bottomleft

Symfony Routing

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

使用Twig过滤器

<img src="{{ asset( 'bundles/app/uploads/' ~ image.id ~ '/' ~ image.file )  | imagine_filter('slide')  }}" />

由我创建的媒体文件夹中的权限。

drwxrwxrwx+  3 root     root  4096 Aug 15 19:05 media

1 个答案:

答案 0 :(得分:0)

我发现了问题。

在配置中,cache_prefix的正确值必须包含tralas slashe

liip_imagine:
    resolvers:
        default:
            web_path:
                web_root: "%kernel.root_dir%/../web"
                cache_prefix: "/media/cache"