perusio / drupal-with-nginx

Running Drupal using nginx: an idiosyncratically crafted bleeding edge configuration.
855 stars 246 forks source link

Authcache support #175

Open davidwhthomas opened 10 years ago

davidwhthomas commented 10 years ago

Authcache provides a standalone implementation of index.php for a partial bootstrap and rapid response. However, this nginx conf prevents that file from being parsed by PHP and returns a 404 instead.

The file name is:

authcache.php

Example request URL:

http://www.example.com/sites/all/modules/contrib/authcache/modules/authcache_p13n/frontcontroller/authcache.php?a=authcache_admin_config&r=frag/form-token&o[q]=

I tried this in drupal.conf without success

location ~* ^.+/authcache\.php {

  ## FCGI backend like php-cgi or php-fpm.
  include apps/drupal/fastcgi_drupal.conf;
  fastcgi_pass phpcgi;        

}

How do you recommend adding to the nginx conf so this PHP file can be correctly requested and processed?

Thanks for the great nginx conf.

DT

davidwhthomas commented 10 years ago

OK, I think I may have found a solution.

I added to drupal.conf, near the end

## Authcache Support.
location ~* ^.+/authcache\.php {
  ## FCGI backend like php-cgi or php-fpm.
  ## Configured for Authcache.
  include apps/drupal/fastcgi_drupal_authcache.conf;
  fastcgi_pass phpcgi;        
}

## Any other attempt to access PHP files returns a 404.
location ~* ^.+\.php$ {
    return 404;
}

Then I copied fastcgi_drupal.conf to fastcgi_drupal_authcache.conf and tweaked it as such (diff output):

9c9
< fastcgi_param SCRIPT_NAME /index.php;
---
> fastcgi_param SCRIPT_NAME /authcache.php;
25c25
< fastcgi_param SCRIPT_FILENAME $document_root/index.php;
---
> fastcgi_param SCRIPT_FILENAME $document_root/sites/all/modules/contrib/authcache/modules/authcache_p13n/frontcontroller/authcache.php;

After that the requests returned a form token, as expected.

Cheers, David

steventhabel commented 10 years ago

I am experiencing same issues; however, applying these changes did not fix my problem. This does not address the issues when authcache.php is used to build the "frag" elements via ajax/esi on authecache module.

davidwhthomas, was there something more you did to get this configuration working?

Thanks a lot for this!

davidwhthomas commented 10 years ago

@cthshabel adding the handler for authcache.php as above (calling fastcgi_drupal_authcache.conf) was all I needed to change for authcache to work. Currently authcache reports ESI is working from the admin test page. Hopefully you can resolve your issue there too.

steventhabel commented 10 years ago

@davidwhthomas thanks for the quick response. And also for writing this up in general. I was very lost diving into authcache, but this is definitely the problem. I temporarily allowed all .php scripts through and sure enough it worked. SO authcache.php not getting through nginx is the problem somewhere.

davidwhthomas commented 10 years ago

@cthshabel make sure the authcache.php path is correct in fastcgi_drupal_authcache.conf here:

fastcgi_param SCRIPT_FILENAME $document_root/sites/all/modules/contrib/authcache/modules/authcache_p13n/frontcontroller/authcache.php;

e.g: perhaps you're not using the "contrib" subfolder or have authcache.php in a different folder there.

Note, I'm using this with PHP-FPM as the fastcgi handler.

I hope that helps.

steventhabel commented 10 years ago

@davidwhthomas you are a saint! my directory was not using "contrib" subfolder. that is what i get for going in and copying line for line. in fear of getting the path wrong, i didn't even pay attention to what yours was.

either way, i changed it to make sure it was mine. restarted nginx. restarted php5-fpm. still no luck :/

included in settings.php --- $conf['authcache_p13n_frontcontroller_path'] = 'authcache.php'; copied authcache.php to drupal root

stumped.

steventhabel commented 10 years ago

@davidwhthomas maybe i am mistaken because it did clear up some errors. but still 404 (Not Found) for these type of url:

https://www.example.com/authcache.php?a=search_box&r=frag/form-token&o[q]=&v=hts7k4 https://www.example.com/authcache.php?a=&r=frag/menu-local-tabs&o[q]=node/61&v=hts7k4 https://www.example.com/authcache.php?a[nh][u][0]=61&r=setting/node-history&o[q]=&v=hts7k4

davidwhthomas commented 10 years ago

Yes, /authcache.php will 404 as the nginx conf is set to the original location in the module folder i.e:

fastcgi_param SCRIPT_FILENAME $document_root/sites/all/modules/authcache/modules/authcache_p13n/frontcontroller/authcache.php;

Sounds like progress though, good luck with the rest of the conf tweaking - getting there.

steventhabel commented 10 years ago

@davidwhthomas definitely will get there :) thanks a lot for your help! means a lot