From 1b43ec431d1becdbd72c9b834ef09b9fa1ef09ac Mon Sep 17 00:00:00 2001 From: Ilia Rostovtsev Date: Sun, 6 Sep 2020 14:22:14 +0300 Subject: [PATCH] Fix better Nginx defaults --- virtual_feature.pl | 23 ++++++++++++++++++----- virtualmin-nginx-lib.pl | 1 + 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/virtual_feature.pl b/virtual_feature.pl index 50ba0c6..6d7ca92 100644 --- a/virtual_feature.pl +++ b/virtual_feature.pl @@ -247,8 +247,10 @@ sub feature_setup &find("fastcgi_param", $server)); &save_directive($server, "fastcgi_param", [ map { { 'words' => $_ } } @params ]); + + # Add location my $ploc = { 'name' => 'location', - 'words' => [ '~', '\.php$' ], + 'words' => [ '~', '\.php(/|$)' ], 'type' => 1, 'members' => [ { 'name' => 'try_files', @@ -257,6 +259,13 @@ sub feature_setup ], }; &save_directive($server, [ ], [ $ploc ]); + + # Add extra directive + &save_directive($server, "fastcgi_split_path_info", + [ { 'name' => 'fastcgi_split_path_info', + 'words' => [ &split_quoted_string('^(.+\.php)(/.+)$') ] + } ]); + &flush_config_file_lines(); &unlock_all_config_files(); @@ -1105,7 +1114,8 @@ sub feature_get_web_php_mode $server || return undef; my @locs = &find("location", $server); my ($loc) = grep { $_->{'words'}->[0] eq '~' && - $_->{'words'}->[1] eq '\.php$' } @locs; + ($_->{'words'}->[1] eq '\.php$' || + $_->{'words'}->[1] eq '\.php(/|$)') } @locs; my $fpmsock = &virtual_server::get_php_fpm_socket_file($d, 1); my $fpmport = $d->{'php_fpm_port'}; if ($loc) { @@ -1174,7 +1184,8 @@ sub feature_save_web_php_mode if ($port) { my @locs = &find("location", $server); my ($loc) = grep { $_->{'words'}->[0] eq '~' && - $_->{'words'}->[1] eq '\.php$' } @locs; + ($_->{'words'}->[1] eq '\.php$' || + $_->{'words'}->[1] eq '\.php(/|$)') } @locs; if ($loc) { &lock_file($loc->{'file'}); &save_directive($loc, "fastcgi_pass", @@ -2304,7 +2315,8 @@ sub feature_restore # Put back old port for PHP server if ($oldd && $oldd->{'nginx_php_port'} ne $d->{'nginx_php_port'}) { - my ($l) = grep { $_->{'words'}->[1] eq '\.php$' } + my ($l) = grep { ($_->{'words'}->[1] eq '\.php$' || + $_->{'words'}->[1] eq '\.php(/|$)') } &find("location", $server); if ($l) { &save_directive($l, "fastcgi_pass", @@ -2426,7 +2438,8 @@ sub feature_clone $d->{'dom'}, 0, 0, 1); # Fix PHP server port, which is incorrect in copied directives -my ($l) = grep { $_->{'words'}->[1] eq '\.php$' } +my ($l) = grep { ($_->{'words'}->[1] eq '\.php$' || + $_->{'words'}->[1] eq '\.php(/|$)') } &find("location", $server); if ($l) { &save_directive($l, "fastcgi_pass", diff --git a/virtualmin-nginx-lib.pl b/virtualmin-nginx-lib.pl index 4d9044b..3c93ba4 100644 --- a/virtualmin-nginx-lib.pl +++ b/virtualmin-nginx-lib.pl @@ -1865,6 +1865,7 @@ sub list_fastcgi_params [ 'SERVER_ADDR', '$server_addr' ], [ 'SERVER_PORT', '$server_port' ], [ 'SERVER_NAME', '$server_name' ], + [ 'PATH_INFO', '$fastcgi_path_info' ], ); my $ver = &get_nginx_version(); if ($ver =~ /^(\d+)\./ && $1 >= 2 ||