Drupal 不生成缩略图

Drupal doesn't generate thumbnails

我不知道为什么 Drupal 停止生成缩略图。所以,我在这样的文件上遇到错误:

/sites/default/files/styles/choices/public/a1531172504.jpg?itok=Wn-VWDKd

尽管完整图片位于:

/sites/default/files/a1531172504.jpg

我正在研究 Nginx、Drupal 7

上次我回答了与图像导数相关的问题,我有缺点所以在这里说清楚。

1.Drupal 核心不会在图片上传时创建图片衍生品 - 事实上。

2.Thumbnail 图片(源自原始图片)是根据 HTTP 请求物理创建的,例如。如果您访问使用图像的列表(当您访问带有缩略图的列表时,衍生品是通过 HTTP 请求即时创建的)

3.To 改变此行为并在通过 CCK 字段上传图像时立即获得衍生图像,您必须使用模块 Imageinfo Cache https://www.drupal.org/project/imageinfo_cache

使用上面的信息表,请重新检查您的网站(转到应显示缩略图的列表,然后检查您的缩略图文件夹)如果图像仍然丢失,请提供更多详细信息,例如:您使用的是 CCK 字段还是它自定义字段,您是否以编程方式创建衍生产品?这里需要一些代码片段来解决你的问题。

另请检查位于 sites/default/files/.htaccess 的 .htaccess(不是一般的 .htaccess) 当你在那里检查文件夹的权限时。

我的修复是禁用 re-enable clean-url。 .../admin/config/search/clean-urls".

我的解决方案是将此行添加到 nginx.conf 文件中:

location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
    expires max;
    log_not_found off;
    try_files $uri $uri/ @rewrite;
}
location @rewrite {
    # not working with Drupal rewrite module: rewrite ^/?(.*?)/?$  /index.php?q=&$args;
    rewrite ^/?(.*?)/?$  /index.php/&$args;
}

我的环境是:

 - docker-compose with nginx (nginx:1.17.4-alpine), drupal   
   (drupal:9.0.6-fpm-alpine) and mysql (mysql:8.0)
 - drupal (9.0.6),    nginx/1.17.4, PHP 7.4.10, MySql 8.0.21

服务器响应 404 error 因为:

  • 图像样式是在drupal收到请求时生成的。
  • Nginx 收到对不在文件系统中的图像的请求;然后 returns 404 将请求重定向到 drupal。

我为nginx.conf提出的规则将图像请求重定向到drupal并在重启网络服务器后解决问题:

docker-compose restart webserver