NGINX configuration options can interfere with generated thumbnails and image styles for uploaded images

Created on 18 March 2020, almost 5 years ago
Updated 29 October 2023, about 1 year ago

I have a fresh composer install of drupal 8 on Freebsd. When I try to upload any jpg/gif/png file to media browser file is uploaded correctly, but thumbnail is not generated.
I can observe the uploaded file in the list of media files but thumbnail is broken.
The uploaded file may be opened correctly and have URL like /sites/default/files/2020-03/filename-11_6.jpg.
The URL of thumbnail is like /sites/default/files/styles/thumbnail/public/2020-03/filename-11_6.jpg?itok=ducg-SU7.
The /sites/default/files/styles/ folder is empty. It have permission 777.
I have try to create appropriate folders structure inside the /sites/default/files/styles folder but thumbnails are still not generated. Manually created folders are removed when I flush at the /admin/config/media/image-styles

How can I force Media to work properly?

WORKAROUND / RESOLUTION:

for Nginx systems:

https://www.drupal.org/project/drupal/issues/3120676#comment-13764129 πŸ’¬ NGINX configuration options can interfere with generated thumbnails and image styles for uploaded images Active

remove nginx directive

# Set images and js to expire in a very long time
location ~* \.(ico|css|pdf|jpg|jpeg|png|gif|js|xml|js|woff|woff2|ttf|svg|eot)$ {
expires 7d;
}

then all thumbnails under sites/default/files/styles/ should be generated and visible.

Remaining tasks

Investigate if feasible to create a patch for hook requirements implementation that would validate a correctly configured Nginx server configuration for styles, this would provide help text if the configuration is determined to be incorrect.
Apache2 doesn't seem to have this problem but perhaps a similar configuration in Apache2 might cause issues, the same hook requirements validation might be best to validate image style creation and file_exists in a generic way for any server type

if feasible, create patch

πŸ’¬ Support request
Status

Active

Version

9.5

Component
MediaΒ  β†’

Last updated 1 day ago

Created by

πŸ‡·πŸ‡ΊRussia a_sh

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States RowboTony

    Update with my own experience. I'm using DDEV with Acquia Migrate Accelerate to move a D7 site to D9. All of my images were broken and wouldn't display. The original images were there, media uploads worked fine, file system permissions were correct, PHP, GD, etc were good.

    The DDEV seconddocroot.conf.example has the following line, when removed, then ddev restart, it worked - my images were back, and now the styles were being properly generated!

    If you are running Nginx, and you have image generation problems, this is still relevant.

    # Expire rules for static content
    # Media: images, icons, video, audio, HTC
    location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
        expires 1M;
        access_log off;
        add_header Cache-Control "public";
    }
    
  • Status changed to Active about 1 year ago
  • πŸ‡ΈπŸ‡°Slovakia poker10

    I am not sure where this directive come from:

    # Set images and js to expire in a very long time
    location ~* \.(ico|css|pdf|jpg|jpeg|png|gif|js|xml|js|woff|woff2|ttf|svg|eot)$ {
      expires 7d;
    }
    

    In all examples/recommended configs for Nginx I see that there is an additional line:

    try_files $uri @rewrite;
    

    See:

    As far as I know, these configs are working without need to remove the whole directive used for caching static content.

    The Issue summary should at least include the full nginx config used on sites experiencing this and clear steps to reproduce. Thanks!

    Core currently does not supply an example nginx config unless this is in ✨ Provide documentation/default server block for Nginx server. Needs work , so I think that this seems like more a Support request (not sure anything can be done here until that issue is committed and there is an estabilished default config supported by core). So I think we can either make this a Support request, or postpone it.

Production build 0.71.5 2024