Skip to content

Instantly share code, notes, and snippets.

@arodbits
Last active May 4, 2018 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arodbits/07be776b14796c29a48f91c7de8a52d0 to your computer and use it in GitHub Desktop.
Save arodbits/07be776b14796c29a48f91c7de8a52d0 to your computer and use it in GitHub Desktop.
NGINX: Handle request with different PHP version driven by the URI resource name
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ^~ /endpoint {
alias /home/www/html;
try_files $uri $uri/ @nested;
location ~ \.php {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_NAME "/index.php";
fastcgi_param DOCUMENT_URI "/index.php";
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
location @nested {
rewrite /endpoint/(.*)$ /endpoint/index.php?/endpoint/$1 last;
}
@csti
Copy link

csti commented May 4, 2018

Nice! How does that "location@nested" block work?

@arodbits
Copy link
Author

arodbits commented May 4, 2018

It rewrites the URI and places any extra parameter in the query_string component of the URI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment