0

I'm runnig drupal on nginx my nginx config file is :

proxy_cache_path /data/nginx/cache keys_zone=my_zone:10m inactive=1d;
# Expires map
map $sent_http_content_type $expires {
    default                    off;
    text/html                  epoch;
    text/css                   max;
    application/javascript     max;
    ~image/                    max;
}

server {
        listen 443 ssl;
        listen [::]:443 ssl;
        ssl_certificate  xxxxxxxxxxxxxxxx;
        ssl_certificate_key xxxxxxxxxxxxxxxx;
        root /var/www/xxxxxxxxxxx/html;
        index index.php  index.html index.htm index.nginx-debian.html;
        server_name xxxxxxxxxxx.com www.xxxx.com;
        expires $expires;
    client_max_body_size 30M;
        keepalive_requests 100000;
        keepalive_timeout 65;

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        types_hash_max_size 2048;

     gzip on;
        gzip_disable "msie6";
 
        gzip_vary on;
        gzip_proxied any;
        gzip_comp_level 6;
        gzip_buffers 16 8k;
        gzip_http_version 1.1;
        gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
        # Specify the minimum length of the response to compress (default 20)
        gzip_min_length 500;

 location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    # Very rarely should these ever be accessed outside of your lan
    location ~* \.(txt|log)$ {
        allow 192.168.0.0/16;
        deny all;
    }

    location ~ \..*/.*\.php$ {
        return 403;
    }

    location ~ ^/sites/.*/private/ {
        return 403;
    }

    # Block access to scripts in site files directory
    location ~ ^/sites/[^/]+/files/.*\.php$ {
        deny all;
    }

    # Allow "Well-Known URIs" as per RFC 5785
    location ~* ^/.well-known/ {
        allow all;
    }

    # Block access to "hidden" files and directories whose names begin with a
    # period. This includes directories used by version control systems such
    # as Subversion or Git to store control files.
    location ~ (^|/)\. {
        return 403;
    }

    location / {
        # try_files $uri @rewrite; # For Drupal <= 6
        try_files $uri /index.php?$query_string; # For Drupal >= 7
    }

    location @rewrite {
        #rewrite ^/(.*)$ /index.php?q=$1; # For Drupal <= 6
        rewrite ^ /index.php; # For Drupal >= 7
    }

    # Don't allow direct access to PHP files in the vendor directory.
    location ~ /vendor/.*\.php$ {
        deny all;
        return 404;
    }

    # Protect files and directories from prying eyes.
    location ~* \.(engine|inc|install|make|module|profile|po|sh|.*sql|theme|twig|tpl(\.php)?|xtmpl|yml)(~|\.sw[op]|\.bak|\.orig|\.save)?$|/(\.(?!well-known).*|Entries.*|Repository|Root|Tag|Template|composer\.(json|lock)|web\.config)$|/#.*#$|\.php(~|\.sw[op]|\.bak|\.orig|\.save)$ {
        deny all;
        return 404;
    }


    # In Drupal 8, we must also match new paths where the '.php' appears in
    # the middle, such as update.php/selection. The rule we use is strict,
    # and only allows this pattern with the update.php front controller.
    # This allows legacy path aliases in the form of
    # blog/index.php/legacy-path to continue to route to Drupal nodes. If
    # you do not have any paths like that, then you might prefer to use a
    # laxer rule, such as:
    #   location ~ \.php(/|$) {
    # The laxer rule will continue to work if Drupal uses this new URL
    # pattern with front controllers other than update.php in a future
    # release.
    location ~ '\.php$|^/update.php' {
        fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
        # Ensure the php file exists. Mitigates CVE-2019-11043
        try_files $fastcgi_script_name =404;
        # Security note: If you're running a version of PHP older than the
        # latest 5.3, you should have "cgi.fix_pathinfo = 0;" in php.ini.
        # See http://serverfault.com/q/627903/94922 for details.
        include fastcgi_params;
        # Block httpoxy attacks. See https://httpoxy.org/.
        fastcgi_param HTTP_PROXY "";
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_intercept_errors on;
        # PHP 5 socket location.
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        # PHP 7 socket location.
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    }

   location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
       proxy_cache my_zone;
       proxy_cache_key "$host$request_uri$http_authorization";
       proxy_cache_valid 404, 302 1m;
       proxy_cache_valid 200 1d;
       add_header X-Cache-Status $upstream_cache_status;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        try_files $uri @rewrite;
        expires max;
        log_not_found off;
    }

    # Fighting with Styles? This little gem is amazing.
    # location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6
    location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
        try_files $uri @rewrite;
    }

    # Handle private files through Drupal. Private file's path can come
    # with a language prefix.
    location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
        try_files $uri /index.php?$query_string;
    }

    # Enforce clean URLs
    # Removes index.php from urls like www.example.com/index.php/my-page --> www.example.com/my-page
    # Could be done with 301 for permanent or other redirect codes.
    if ($request_uri ~* "^(.*/)index\.php/(.*)") {
        return 307 $1$2;
    }

}

when an image uploaded it's image style not generated.also when i check style folder that's not exist and not generated. this is my permission folders :

sites -----> 755
default ---- > 775
files --- > 775

owner/group of my site file is www-data www-data

also I added two lines to settings.php:

$config['image.settings']['suppress_itok_output'] = TRUE;
$config['image.settings']['allow_insecure_derivatives'] = TRUE;

even I used "drush image-flush" and my image style flushed but styles not regenerated.

1

The image derivative is created when it's requested, not when the image to which the image style is applied is uploaded.

When the URL for an image derivative is accessed, ImageStyleDownloadController::deliver() is invoked, and the image derivative is created, if it doesn't already exist.

1
  • this problem maked after changed web server , before this problem I called images with views block. i call image field and show image with image style, but after change web server , drupal cant generate image in image style folder. – Hassan Monfared Jan 27 at 10:41
0
  1. create sites/default/files/styles folder manually
  2. set its permissions to 775
  3. create .htaccess file with following content:
    <Files *>
      SetHandler none
    </Files>

Source

1
  • this is by default htaccess : code Options -Indexes -ExecCGI -Includes -MultiViews SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006 <Files *> SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003 </Files> <IfModule mod_php5.c> php_flag engine off </IfModule> code I substitute this with your answer but not worked – Hassan Monfared Jan 27 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.