Skip to content

Instantly share code, notes, and snippets.

@arodbits
Last active May 4, 2018
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@csti csti commented May 4, 2018

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

@arodbits

This comment has been minimized.

Copy link
Owner Author

@arodbits 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