Last active
May 4, 2018 19:04
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
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
Nice! How does that "location@nested" block work?