drupal-with-nginx
drupal-with-nginx copied to clipboard
Add support for module js - High-performance JavaScript callback handler
Need help to modify NGINX configuration to add support for the the module js.
This module allows to use a really light and customized Drupal bootstrap for AJAX callback. The gain of performance is huge.
To realize that, the module doesn't use index.php form drupal, but its own js.php script that we need to insert inside Drupal root directory.
All AJAX callbacks using this module must start with directory /js/mymodule/callback-name. Baraccuda provides this modification to their project: http://cgit.drupalcode.org/sandbox-omega8cc-1074910/commit/?id=1d5141b
###
### Support for http://drupal.org/project/js module.
###
location ^~ /js/ {
location ~* ^/js/ {
rewrite ^/(.*)$ /js.php?q=$1 last;
}
}
There is now official (https://www.drupal.org/node/2834257) NGINX rewrite rules for the 7.x-2.x
branch of the JS Callback Handler module:
###
### Support for https://www.drupal.org/project/js module.
###
location ~* "^/(?:[a-z]{2}(?:-[A-Za-z]{2,4})?/)?(?:js|js/.*)$" {
rewrite ^/(.*)$ /js.php?q=$1 last;
}
### Non-clean URLs (query based, only uncomment if needed).
# if ($query_string ~ "(?:^|&)q=((?:[a-z]{2}(?:-[A-Za-z]{2,4})?/)?(?:js|js/.*))") {
# rewrite ^/(.*)$ /js.php?q=$1 last;
#}
It also, currently, adds instructions on how to add support for this project:
### PHP-FPM (using https://github.com/perusio/drupal-with-nginx)
###
### 1. Copy `apps/drupal/fastcgi_drupal.conf` to `apps/drupal/fastcgi_js.conf`.
### 2. Inside `fastcgi_js.conf`, rename all cases of `index.php` to `js.php`.
###
location ^~ /js.php {
tcp_nopush off;
keepalive_requests 0;
access_log off;
try_files $uri =404; ### check for existence of php file first
include apps/drupal/fastcgi_js.conf;
fastcgi_pass phpcgi;
}
In hindsight, it'd be nice if this was automatically supported by this project.
I actually went ahead and made this a little easier to implement. Existing sites (once that PR is merged) can update to the latest code and just add the following to their site's server
code block (before the apps/drupal/drupal.conf
include and $not_allowed_method
check):
#################################################################
### Configuration for Drupal 7 sites that use the JS Callback
### Handler module: https://www.drupal.org/project/js. This
### should be above the $not_allowed_method (since the JS module
### handles these) and above the normal drupal.conf include.
#################################################################
include apps/drupal/drupal_js.conf;