Issue with image thumbnails appearing (image styles)

Events happening in the community are now at Drupal community events on www.drupal.org.
x.algorithm's picture

I am unable to get thumbnails and other images that use image styles to work.

http://ursusfightclub.org/people/profile/makoto

'Taking the field in Belmonte' should be the alt tag for the image.

Users are also unable to reset passwords. It returns "You are not authorized to access this page."

I believe they are related to rewrite and nginx

I've checked and utilized https://groups.drupal.org/node/273378
I've attempted to implement Perusio's config http://github.com/perusio/drupal-with-nginx
However, I am using Centos 6.5. and it does not come with the http://wiki.nginx.org/HttpSetMiscModule module that Perusio's config requires for lua based rewrites; if I understand it correctly. I might be misunderstanding it.

The site did work on apache, but it was slow and I changed over to nginx and everything else seems ok.

Configs and all the things you'll ask for below.

nginx -V returns

nginx version: nginx/1.6.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_spdy_module --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

Config on the vhost:

server {
  server_name ursusfightclub.org www.ursusfightclub.org medievalcombat.net www.medievalcombat.net;
  root /var/www/combat; ## <-- Your only path reference.
  error_log /var/log/nginx/combat-error.log debug;
    access_log /var/log/nginx/combat-access.log;
    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)$ {
    deny all;
    }
  location ~ \..*/.*\.php$ {
    return 403;
    }
  location / {
    # This is cool because no php is touched for static content
      index index.php index.htm index.html;
      try_files $uri @rewrite;
    }
    location @rewrite {
      # Some modules enforce no slash (/) at the end of the URL
      # Else this rewrite block wouldn't be needed (GlobalRedirect)
      rewrite ^/(.*)$ /index.php?q=$1 last;
    }
    location ~ \.php$ {
      fastcgi_pass   unix:/tmp/php5-fpm.sock;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include /etc/nginx/fastcgi_params;
    }
   #Fighting with ImageCache? This little gem is amazing.
    location ~* /sites/.*/files/imagecache/ {
    try_files $uri @rewrite;
    }
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
      expires max;
      log_not_found off;
    }
    location ~* /sites/.*/files/styles/ {
      access_log off;
      expires 30d;
      try_files $uri @rewrite;
    }

Thank you in advance for assistance
xalg

Comments

Quick fix

mikeytown2's picture

https://www.drupal.org/project/imageinfo_cache will pre-generate the images and has a drush script to generate as well.

However, I am using Centos

Garrett Albright's picture

However, I am using Centos 6.5. and it does not come with the http://wiki.nginx.org/HttpSetMiscModule module that Perusio's config requires for lua based rewrites; if I understand it correctly. I might be misunderstanding it.

I think you are, because Perusio's config doesn't require that module, as far as I'm aware, and that module doesn't have anything to do with Lua anyway. I've got Perusio's config working on a site hosted on CentOS and I don't recall having to install any unusual modules to do so.

That being said, Perusio's config contains a lot of config for Nginx modules and stuff that I have no use for and don't install, like MPEG-4 streaming and such, and that Nginx complains about if you try to start it up without those modules installed. The solution is to simply comment out that section of the config rather than use an entirely separate config, though.

You don't need

perusio's picture

any Lua module whatsoever. It works out of the box.

Fixed:Styles directory is different than default

x.algorithm's picture

So, after some trial and error with the reg ex for the styles directory I discovered that my image style directories and images were not simply in sites/default/files/styles. They were in sites/default/files/styles/stylename/public/
So, I modified the styles location block regex to: location ~* /sites/./files/styles/./public/

restart nginx, drush cc'd all and refreshed the page and all is well.

Thanks for all of your help!

I also tried perusio's config, again, and I get a black screen each time. It wasn't a 500 error and setting debug on in nginx didn't reveal anything in /var/log/nginx. I am not sure what is not working on my server.

I'd like Perusio's config much better than my barebones one.

Location Block Priority

mesch's picture

Nginx stops evaluating regex location blocks when the first match is found, so order matters. Right now Nginx is stopping at/selecting this block:

    location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
      expires max;
      log_not_found off;
    }

Try reversing your last two location blocks so that the "styles" location regex comes first. If you look at perusio's config this is the ordering he's used (see the placement of the ~* /files/styles location block in /apps/drupal/drupal.conf).

See http://nginx.org/en/docs/http/ngx_http_core_module.html#location

Then regular expressions are checked, in the order of their appearance in the configuration file. The search of regular expressions terminates on the first match, and the corresponding configuration is used.

I can also echo what Garrett said above re: needing to chisel away at perusio's default config to keep only the features you need. Version control helps here. I can also confirm I've never needed lua enabled.

Nginx

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: