[5.7] Remove fastcgi_split_path_info from nginx config #4867
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello @taylorotwell!
You've probably missed my previous PR's (#4847) comments, let me summarize to create a whole picture.
fastcgi_split_path_info
What is purpose of the
fastcgi_split_path_info
nginx directive?It constructs the
$fastcgi_path_info
variable from the given regex (with exactly 2 capture groups).Most widely used value is
^(.+\.php)(/.+)$
. (nginx docs)What is effect of using
fastcgi_split_path_info
?The
$fastcgi_path_info
value will be set to the processed path's portion after the.php
extension.Example:
https://laravel.com/test.php/foo/bar
=>/foor/bar
.How can I use the
$fastcgi_path_info
variable?Now we may have some value assigned to
$fastcgi_path_info
, but we have to pass it to PHP via thePATH_INFO
variable (the default/etc/nginx/fastcgi_params
file does not handle it).The standard way to do that:
fastcgi_param PATH_INFO $fastcgi_path_info
.What is prerequisite of using
fastcgi_split_path_info
?Since the only use-case is getting the substring (routing) after the
.php
file, we have to create a location block which handles such paths.Most widely used location block to do that:
Should I use the
fastcgi_split_path_info
?Only if you have to deal with
/index.php/foo/bar
style routes (orslash arguments
as Moodle calls it).Typical applications which require it: Moodle, older Joomla!, Drupal (only update route), Magento (only update route) or any legacy stuff.
Some applications which support it: Symfony (note the
internal
directive), Slim (note the missing$
)Some applications which don't support it: Yii 2, Zend, CodeIgniter, CakePHP, WordPress
Can I see some example?
Example reques
#1
:https://laravel.com/test.php
fastcgi_split_path_info
:$fastcgi_script_name
:/test.php
$fastcgi_path_info
:no value
fastcgi_split_path_info
(value:^(.+\.php)(/.+)$
):$fastcgi_script_name
:/test.php
$fastcgi_path_info
:no value
Example request
#2
:https://laravel.com/test.php/foo/bar
fastcgi_split_path_info
:$fastcgi_script_name
:/test.php/foo/bar
$fastcgi_path_info
:no value
fastcgi_split_path_info
(value:^(.+\.php)(/.+)$
):$fastcgi_script_name
:/test.php
$fastcgi_path_info
:/foo/bar
fastcgi_split_path_info
× LaravelWhat's the issue with nginx configuration?
The Deployment documentation of Laravel suggests the following nginx PHP location block:
Issues:
.php
(e.g./test.php
), so it won't process a route with slash arguments (e.g./test.php/foo/bar
)..php$
paths will be processed the there is no point of usingfastcgi_split_path_info
.fastcgi_split_path_info
directive, the generated$fastcgi_path_info
(without value in this case) isn't used anywhere.Solutions
#1
Get rid offastcgi_split_path_info
The most obvious way to handle this anomaly is removing the
fastcgi_split_path_info
directive, as I suggested in this PR.The final location block would be:
#2
Allow slash argumentsAnother way to make the configuration useful is extending the location regex to:
[^/]\.php(/|$)
The final location block would be:
(
#3
Hybrid solution)Laravel's
Illuminate\Http\Request
class extendsSymfony\Component\HttpFoundation\Request
class, which handles thePATH_INFO
variable if present, but also can construct it from the url. We can get rid offastcgi_split_path_info
directive (since we currently do not pass thePATH_INFO
variable to PHP) and allow the slash arguments processing location regex.Thanks for reading this.
What do you think @taylorotwell?
P.S. Sorry for the duplicate PR.