1

My current configuration rewrites all php pages to /index.php?$query_string, I need this to work for a specific path, but when using a location block for this, once the path has been rewritten it no longer matches. Is there a way to to forward a request to fpm and rewrite the URI in same location block without redirecting? Or an alternative that will accomplish what I want?

Here is my specific code:

location /civicrm/group {
    location ~ \.php$ {
        fastcgi_send_timeout 0;
        fastcgi_read_timeout 0;
        include snippets/fastcgi-common.conf;
        fastcgi_param HTTPS 'on';
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }
    try_files $uri @drupal;
}

location ~ \.php$ {
    include snippets/fastcgi-modify.conf;
    include snippets/fastcgi-common.conf;
    fastcgi_param HTTPS 'on';
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}

location @drupal {
    try_files $uri /index.php?$query_string;
}

The problem is this means I lose information on the original base path and can no longer match the original location, for example:

  1. Request /civicrm/group?reset=1
  2. Match location /some/path, this is where I would like to change the settings for php-fpm.
  3. I need to change the URI, so I rewrite to /index.php?$query_string
  4. Now, I start matching from the beginning, but now the location /some/path?reset=1 wont match (problem)
  5. So I match the regular php location block.
johnramsden
  • 131
  • 1
  • 4

1 Answers1

1

If there are no static files under this path, you could send all requests directly to index.php with:

location /civicrm/group {
    try_files /index.php =404;

    fastcgi_send_timeout 0;
    fastcgi_read_timeout 0;
    include snippets/fastcgi-common.conf;
    fastcgi_param HTTPS 'on';
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}

Notice that the /index.php term has been moved so that it is no longer the last parameter and no longer contains the query string. See this document for details.

Richard Smith
  • 12,834
  • 2
  • 21
  • 29