From cf6a0ece77bfbc43eeae2b1759c0d9b82fb8290e Mon Sep 17 00:00:00 2001 From: iliajie Date: Tue, 20 Sep 2022 00:10:19 +0300 Subject: [PATCH] Add ability to display PHP files in disabled mode ; preserve a block --- virtual_feature.pl | 47 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/virtual_feature.pl b/virtual_feature.pl index 8f88aa9..ba5fcd8 100644 --- a/virtual_feature.pl +++ b/virtual_feature.pl @@ -272,9 +272,12 @@ sub feature_setup 'words' => [ '~', '\.php(/|$)' ], 'type' => 1, 'members' => [ - { 'name' => 'try_files', - 'words' => [ '$uri', '$fastcgi_script_name', '=404' ], - }, + { 'name' => 'try_files', + 'words' => [ '$uri', '$fastcgi_script_name', '=404' ], + }, + { 'name' => 'default_type', + 'words' => [ 'application/x-httpd-php' ], + } ], }; &save_directive($server, [ ], [ $ploc ]); @@ -1274,16 +1277,19 @@ sub feature_save_web_php_mode # Update the port in the config, if changed if (!$loc) { &lock_file($server->{'file'}); - $loc = { 'name' => 'location', - 'words' => [ '~', '\.php(/|$)' ], - 'type' => 1, - 'members' => [ - { 'name' => 'try_files', - 'words' => [ '$uri', '$fastcgi_script_name', - '=404' ], - }, - ], - }; + $loc = + { 'name' => 'location', + 'words' => [ '~', '\.php(/|$)' ], + 'type' => 1, + 'members' => [ + { 'name' => 'default_type', + 'words' => [ 'application/x-httpd-php' ], + }, + { 'name' => 'try_files', + 'words' => [ '$uri', '$fastcgi_script_name', '=404' ], + }, + ], + }; &save_directive($server, [ ], [ $loc ]); &flush_file_lines($server->{'file'}); &unlock_file($server->{'file'}); @@ -1300,7 +1306,20 @@ sub feature_save_web_php_mode # Remove the location block if ($loc) { &lock_file($server->{'file'}); - &save_directive($server, [ $loc ], [ ]); + my $locdeftype = + { 'name' => 'location', + 'words' => [ '~', '\.php(/|$)' ], + 'type' => 1, + 'members' => [ + { 'name' => 'default_type', + 'words' => [ 'text/plain' ], + }, + { 'name' => 'try_files', + 'words' => [ '$uri', '$fastcgi_script_name', '=404' ], + }, + ], + }; + &save_directive($server, [ $loc ], [ $locdeftype ]); &flush_file_lines($server->{'file'}); &unlock_file($server->{'file'}); &virtual_server::register_post_action(\&print_apply_nginx);