LiipImagineBundle 无法使用 nginx 进行生产

LiipImagineBundle not working on production with nginx

我在 Symfony 5.2 上使用 LiipImagineBundle 2.3.1,但 id 不会在生产环境中创建缓存文件,抛出 404。它在开发上工作得很好。

如果我 运行 php bin/console liip:imagine:cache:resolve image.jpg --filter=filter_name 它确实创建了图像,所以我猜问题与 nginx 有关。

nginx版本为1.18.0 PHP 版本为 7.4.3

liip_imagine.yaml:

liip_imagine:

    driver: "gd"

    resolvers:    
      default:    
        web_path: ~   

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

nginx 配置:

server {
    server_name default_server;
    root /var/www/mysite/public;
   
    location / {
        try_files $uri @rewrite_framework_symfony;
    }

    location @rewrite_framework_symfony {
        rewrite ^(.*)$ /index.php/ last;
    }

    location ~ ^/index\.php(/|$) {
        fastcgi_pass unix:/var/run/php/php7.4-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 ~*  \.(jpg|jpeg|png|gif|ico)$ {
        expires 365d;
        log_not_found off;
        access_log off;
        try_files $uri $uri/ /index.php?$query_string;
    }    
}

有人帮我吗?

我刚刚解决了这个问题。

/media/cache 获得了 nginx 用户 root 而不是 www-data 的权限。

$ chown -R www-data:www-data media/cache/