Skip to content

Commit

Permalink
Fix better Nginx defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
iliajie committed Sep 6, 2020
1 parent d932bba commit 1b43ec4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
23 changes: 18 additions & 5 deletions virtual_feature.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions virtualmin-nginx-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down

0 comments on commit 1b43ec4

Please sign in to comment.