Learn about Centmin Mod LEMP Stack today
Become a Member

Drupal Drupal Imagecache 404

Discussion in 'Blogs & CMS usage' started by Francisco Esteves, Jan 19, 2016.

  1. Francisco Esteves

    Francisco Esteves New Member

    23
    2
    3
    Sep 4, 2014
    Ratings:
    +2
    Local Time:
    7:14 AM
    Anyone use Drupal 7 with imagecache in centminmod?

    We have try for days and cant find any rewrite rule that make this feature work. We have 404 in this images.

    Code:
      # prevent access to ./directories and files
      location ~ (?:^|/)\. {
      deny all;
      }
    
      location / {
      try_files $uri $uri/ /index.php?q=$request_uri;
      }
    
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/php.conf;
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    
    location ~* /files/styles/ {
      access_log off;
      expires 30d;
    try_files $uri $uri/ /index.php?q=$request_uri;
    }
    
    location ~* /system/files/styles/ {
      access_log off;
      expires 30d;
    try_files $uri $uri/ /index.php?q=$request_uri;
    }
    
    Any idea? Drupal URLs works fine but images not.
    Cant using this rules: Images are missing in drupal 7 working on nginx | Drupal.org or Image styles when imported from apache not creating | Drupal Groups

    Thanks,

     
  2. eva2000

    eva2000 Administrator Staff Member

    55,163
    12,249
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,825
    Local Time:
    4:14 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    don't use drupal, but would staticfiles.conf include at /usr/local/nginx/conf/staticfiles.conf interfere ?

    the include file is included in all vhosts by default and matches on image extensions and static file extensions so you may need to comment out location extension matches or create your own copy of /usr/local/nginx/conf/staticfiles.conf i.e. /usr/local/nginx/conf/staticfiles-drupal.conf and replace your drupal nginx vhost include with that one with altered/commented out settings and leave other nginx vhosts with default /usr/local/nginx/conf/staticfiles.conf

    Code:
        # prepare for letsencrypt
        # https://community.centminmod.com/posts/17774/
        location ~ /.well-known {
            location ~ /.well-known/acme-challenge/(.*) {
                    default_type text/plain;
                        charset off;
            }
        }
    
        location ~* \.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {
            gzip_static off;
            #add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
            access_log off;
            expires 30d;
            break;
            }
    
        location ~* \.(js)$ {
            #add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
            access_log off;
            expires 30d;
            break;
            }
    
        location ~* \.(css)$ {
            #add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
            access_log off;
            expires 30d;
            break;
            }
    
        location ~* \.(html|htm|txt)$ {
            #add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
            access_log off;
            expires 1d;
            break;
            }
    
        location ~* \.(eot|svg|ttf|woff|woff2)$ {
            #add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
            access_log off;
            expires 30d;
            break;
            }
     
  3. Ahmad

    Ahmad Active Member

    209
    80
    28
    Apr 13, 2015
    Ratings:
    +150
    Local Time:
    8:14 AM
    1.9.9
    10.1.10
  4. Francisco Esteves

    Francisco Esteves New Member

    23
    2
    3
    Sep 4, 2014
    Ratings:
    +2
    Local Time:
    7:14 AM
    Hello,
    We have commented /usr/local/nginx/conf/staticfiles.conf and now have a 403 error.

    Have try change try_files $uri $uri/ /index.php?q=$request_uri; to try_files $uri $uri/ /index.php?q=$uri&$args; or try_files $uri $uri/ /index.php; and have same problem.

    Thanks,
     
  5. Francisco Esteves

    Francisco Esteves New Member

    23
    2
    3
    Sep 4, 2014
    Ratings:
    +2
    Local Time:
    7:14 AM
    We have try this:

    Code:
    location ~* files/styles {
      access_log off;
      expires 30d;
      try_files $uri @rewrite;
    }
    
    location @rewrite {
      rewrite ^ /index.php last;
    }
    
    or
    Code:
      location ~ ^/sites/.*/files/styles/ {
      try_files $uri @rewrite;
      }
    
    location @rewrite {
      rewrite ^ /index.php last;
    }
    And still get a 403
     
  6. eva2000

    eva2000 Administrator Staff Member

    55,163
    12,249
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,825
    Local Time:
    4:14 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    post your full nginx vhost and also ensure file and directory permissions are correct on your files
     
  7. Francisco Esteves

    Francisco Esteves New Member

    23
    2
    3
    Sep 4, 2014
    Ratings:
    +2
    Local Time:
    7:14 AM
    Hello,
    All config. In # is the rules we have try without success.
    Code:
    server {
      server_name xxxxx.com www.xxxxx.com;
    
      access_log /home/nginx/domains/xxxxx.com/log/access.log combined buffer=256k flush=60m;
      error_log /home/nginx/domains/xxxxx.com/log/error.log;
    
      root /home/nginx/domains/xxxxx.com/public;
    
      location / {
      try_files $uri $uri/ /index.php?q=$request_uri;
      }
    
      include /usr/local/nginx/conf/php.conf;
    
    #location ~* files/styles {
    #  access_log off;
    #  expires 30d;
    #  try_files $uri @rewrite;
    #}
    
      location ~ ^/sites/.*/files/styles/ {
      try_files $uri @rewrite;
      }
    
    location @rewrite {
      rewrite ^ /index.php last;
    }
    #location ~* /files/styles/ {
    #  access_log off;
    #  expires 30d;
    #try_files $uri $uri/ /index.php?q=$request_uri;
    #}
    
    #location ~* /system/files/styles/ {
    #  access_log off;
    #  expires 30d;
    #try_files $uri $uri/ /index.php?q=$request_uri;
    #}
    
    }
    
     
  8. Francisco Esteves

    Francisco Esteves New Member

    23
    2
    3
    Sep 4, 2014
    Ratings:
    +2
    Local Time:
    7:14 AM
    Hello,
    We have double checked and its not a permission problem.

    [root@server public]# chown -R nginx:nginx *
    [root@server public]# find /home/nginx/domains/xxxxxxxxx.com/public -type f -print0 | xargs -0 chmod 644
    [root@server public]# find /home/nginx/domains/xxxxxxxxx.com/public -type d -print0 | xargs -0 chmod 755

    Note: Obviously the site is work fine without problem in Apache
     
  9. eva2000

    eva2000 Administrator Staff Member

    55,163
    12,249
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,825
    Local Time:
    4:14 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    maybe Image styles when imported from apache not creating | Drupal Groups ?
    is imagecache just a nginx proxycache setup ?
     
    Last edited: Jan 19, 2016