From 75247983852df9c412a61878c49cb52c49aba07e Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 19 Jan 2024 21:21:36 +0800 Subject: [PATCH] =?UTF-8?q?php=E9=85=8D=E7=BD=AE=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/php/conf/enable-php-upstream.conf | 2 +- plugins/php/conf/enable-php.bak.conf | 9 ++++ plugins/php/conf/enable-php.conf | 3 +- plugins/php/index.py | 50 +++++++++++++++-------- 4 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 plugins/php/conf/enable-php.bak.conf diff --git a/plugins/php/conf/enable-php-upstream.conf b/plugins/php/conf/enable-php-upstream.conf index 880b1bb0b..22b30badf 100644 --- a/plugins/php/conf/enable-php-upstream.conf +++ b/plugins/php/conf/enable-php-upstream.conf @@ -1,4 +1,4 @@ -upstream UP-PHP{$PHP_VERSION} { +upstream UPSTREAM-PHP{$PHP_VERSION} { server unix:/tmp/php-cgi-{$PHP_VERSION}.sock; server unix:/tmp/php-cgi-{$PHP_VERSION}.backup.sock; } \ No newline at end of file diff --git a/plugins/php/conf/enable-php.bak.conf b/plugins/php/conf/enable-php.bak.conf new file mode 100644 index 000000000..2046ac2cb --- /dev/null +++ b/plugins/php/conf/enable-php.bak.conf @@ -0,0 +1,9 @@ +set $PHP_ENV 1; +location ~ [^/]\.php(/|$) +{ + try_files $uri =404; + fastcgi_pass unix:/tmp/php-cgi-{$PHP_VERSION}.sock; + fastcgi_index index.php; + include fastcgi.conf; + include {$SERVER_PATH}/web_conf/php/pathinfo.conf; +} \ No newline at end of file diff --git a/plugins/php/conf/enable-php.conf b/plugins/php/conf/enable-php.conf index 2046ac2cb..c67ba4f3a 100644 --- a/plugins/php/conf/enable-php.conf +++ b/plugins/php/conf/enable-php.conf @@ -2,7 +2,8 @@ set $PHP_ENV 1; location ~ [^/]\.php(/|$) { try_files $uri =404; - fastcgi_pass unix:/tmp/php-cgi-{$PHP_VERSION}.sock; + #fastcgi_pass unix:/tmp/php-cgi-{$PHP_VERSION}.sock; + fastcgi_pass UPSTREAM-PHP{$PHP_VERSION}; fastcgi_index index.php; include fastcgi.conf; include {$SERVER_PATH}/web_conf/php/pathinfo.conf; diff --git a/plugins/php/index.py b/plugins/php/index.py index 4db863677..020aa8d64 100755 --- a/plugins/php/index.py +++ b/plugins/php/index.py @@ -162,17 +162,21 @@ def makeOpenrestyConf(): sdir = mw.getServerDir() dst_dir = sdir + '/web_conf/php' - dst_dir_conf = sdir + '/web_conf/php/conf' if not os.path.exists(dst_dir): mw.execShell('mkdir -p ' + dst_dir) + dst_dir_conf = sdir + '/web_conf/php/conf' if not os.path.exists(dst_dir_conf): mw.execShell('mkdir -p ' + dst_dir_conf) - d_pathinfo = sdir + '/web_conf/php/pathinfo.conf' - if not os.path.exists(d_pathinfo): - s_pathinfo = getPluginDir() + '/conf/pathinfo.conf' - shutil.copyfile(s_pathinfo, d_pathinfo) + dst_dir_upstream = sdir + '/web_conf/php/upstream' + if not os.path.exists(dst_dir_upstream): + mw.execShell('mkdir -p ' + dst_dir_upstream) + + dst_pathinfo = sdir + '/web_conf/php/pathinfo.conf' + if not os.path.exists(dst_pathinfo): + src_pathinfo = getPluginDir() + '/conf/pathinfo.conf' + shutil.copyfile(src_pathinfo, dst_pathinfo) info = getPluginDir() + '/info.json' content = mw.readFile(info) @@ -184,19 +188,31 @@ def makeOpenrestyConf(): dfile = sdir + '/web_conf/php/conf/enable-php-' + x + '.conf' if not os.path.exists(dfile): if x == '00': - mw.writeFile(dfile, 'set $PHP_ENV 0;') + mw.writeFile(dfile, '') else: - w_content = contentReplace(tpl_content, x) - mw.writeFile(dfile, w_content) - - # php-fpm status - # for version in phpversions: - # dfile = sdir + '/web_conf/php/status/phpfpm_status_' + version + '.conf' - # tpl = getPluginDir() + '/conf/phpfpm_status.conf' - # if not os.path.exists(dfile): - # content = mw.readFile(tpl) - # content = contentReplace(content, version) - # mw.writeFile(dfile, content) + content = contentReplace(tpl_content, x) + mw.writeFile(dfile, content) + + upstream_tpl = getPluginDir() + '/conf/enable-php-upstream.conf' + upstream_tpl_content = mw.readFile(upstream_tpl) + for x in phpversions: + dfile = sdir + '/web_conf/php/upstream/enable-php-' + x + '.conf' + if not os.path.exists(dfile): + if x == '00': + mw.writeFile(dfile, '') + else: + content = contentReplace(upstream_tpl_content, x) + mw.writeFile(dfile, content) + + vhost_dir = mw.getServerDir() + '/web_conf/nginx/vhost' + write_php_upstream_conf = mw.getServerDir()+'/web_conf/php/upstream/*.conf;' + if not os.path.exists(vhost_dir): + mw.execShell('mkdir -p ' + vhost_dir) + + vhost_php_upstream = vhost_dir+'/0.php_upstream.conf' + if not os.path.exists(vhost_php_upstream): + mw.writeFile(vhost_php_upstream,'include '+write_php_upstream_conf) + def phpPrependFile(version):