nginx clean urls and image styles..

elfanjo's picture

Hi folks,

I've been banging my head on that one for a fex days now!

Basically clean urls test fails in admin/config/search/clean-urls which I assume is normal in a nginx environment (?)

No biggy as I force it in setting.php

When clean urls are turned on everything works as expected but image styles.
images are getting uploaded in sites/default/files as one would expect, but are not being generated when I visit the page.

My assumption is that something is broken with clean urls.

So the question is do you guys pass the clean urls test in admin/config/search/clean-urls with nginx?

Comments

nginx can pass the clean-urls

brianmercer's picture

nginx can pass the clean-urls test with the appropriate config.

hmmmm

elfanjo's picture

Right..

In that case is there any way to know what's going wrong? I get no log messages for that

Yes

perusio's picture

the debug log.

Still no luck

elfanjo's picture

Sorry guys but still no luck

Here is a bit more insight on my setup

nginx -V

nginx: nginx version: nginx/1.0.6
nginx: TLS SNI support enabled
nginx: configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-debug --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=/usr/src/nginx/source/nginx-1.0.6/debian/modules/nginx-echo --add-module=/usr/src/nginx/source/nginx-1.0.6/debian/modules/nginx-upstream-fair

nginx.conf for the domain (included in the main nginx.conf)

  include /etc/nginx/include/expires-header;
  include /etc/nginx/include/deny-rules;

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

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

  # This matters if you use drush
  location = /backup {
      deny all;
  }

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

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

  location / {
     index index.html index.htm index.php;
     try_files $uri @rewrite;
     expires max;
  }

  location ~* files/styles/ {
     expires max;
     try_files $uri @rewrite;
  }

  location ~* files/generate {
     expires max;
     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 last;
  }

  location ~ \.php$ {
     fastcgi_split_path_info ^(.+\.php)(/.+)$;
     # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
     include /etc/nginx/fastcgi_params;
     fastcgi_pass unix:$base/php.sock;
  }

  location ~* ^.+\.(js|css|png|jpg|jpeg|gif|ico|xml)$ {
     expires max;
     root /home/hosting/domains/secf/#My_Domain#/docroot;
  }

Do you guys see anything that pops out as invalid ?

Drupal 6 or 7? Here's the

brianmercer's picture

Drupal 6 or 7?

Here's the code that checks clean url availability: http://api.drupal.org/api/drupal/modules!system!system.admin.inc/function/system_clean_url_settings/7

It sends a request to /admin/config/search/clean-urls/check and tests for a 200 response code. Does your site return 200 to that?

nope

elfanjo's picture

yeah sorry It's on Drupal 7 :)

http status seems to be 302 (it's the POST right?)!!
(I get 200 on the GET request)

But thanks so much for pointing that out!
Getting closer...

$request->code gives me "-111" on clean urls test -> ie network error :(

That made me notice that the "drupal_http_request_fails" flag is set to TRUE !!!

now that makes sense... kind of...

the site is updating fine and http requests seems to go out :\

suggests an iptables problem?

ok more on that. if I call

elfanjo's picture

ok more on that.

if I call /admin/config/search/clean-urls/check directly something odd happens:

first I get the precious 200, second I get a json string : "{"status":true}"

why on earth is this stupid test failing!!

...

elfanjo's picture

@stream_socket_client($socket, $errno, $errstr, $options['timeout']); fails!

and that seems to be the problem

You should get the json

brianmercer's picture

You should get the json string with a 200 code.

http://api.drupal.org/api/drupal/modules!system!system.module/function/system_menu/7 has that menu callback for admin/config/search/clean-urls/check.

The test uses base_url. Is

brianmercer's picture

The test uses base_url. Is that set in your settings.php file? Is it set correctly or is it rewriting from www or something?

$base_url contains the domain

elfanjo's picture

$base_url contains the domain name like:

$base_url = 'http://www.#domain-name#.com';

and in @stream_socket_client($socket, $errno, $errstr, $options['timeout'])

$socket is the same -> tcp://www.#domain-name#.com

Do

perusio's picture

you have some theme with JS that makes use of a lot of AJAX? I had a problem like that some time ago and it was due to the admin theme that didn't let the request finish.

Cf. http://drupal.org/node/936766

@perusio

elfanjo's picture

Will investigate on that too :)
I use the default admin theme

seems similar to this

making progress

elfanjo's picture

Although I have not been able to fix this problem yet I am getting closer.

I post this for people who are still having the same problem.

With "clean_url=1" the image_style_url becomes:
http://#my_domain#/sites/default/files/styles/#image_style_name#/public/#image_name#.jpg --> does not work
but if I modify the above and paste it in my browser like so:
http://#my_domain#/index.php?q=sites/default/files/styles/#image_style_name#/public/#image_name#.jpg

http://#my_domain#/?q=sites/default/files/styles/#image_style_name#/public/#image_name#.jpg also works

the image style is created just fine. then obviously the first url finds the image that has been copied this time.

Still a rewrite issue to me but I can't seem to find the correct rewrite in nginx.conf

This is how I rewrite this bit:

  location ~* files/styles {
     expires max;
     try_files $uri @rewrite;
  }

  location ~* files/generate {
     expires max;
     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 last;
  }

okayyyy

elfanjo's picture

ok I resign..

I just fixed the url by overriding image_style_url function in my template.php

elfanjo, I had the exact same

Stan Shevchuk's picture

elfanjo,

I had the exact same situation today where clean URLs were supposed to work but the test was failing (and I knew they were working as it was a devel copy of the site running on the same server with same configs).

And then, after looking at the debug log, it struck me - I put the site under password (auth_basic) and Drupal was not getting the status response from Nginx and failing! Disabling password protection for a minute and re-running the test made the problem go away.

regarding sef urls

elfanjo's picture

@Stan

thanks for the feedback.

regarding sef urls it turned out that socket outbound calls were blocked in my iptables, hence failling the test. with that in mind forcing sef urls was the way to go and it just works ;)

Nginx

Group organizers

Group notifications

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

Hot content this week