From 24338accb49990bfbd88789c200175b88595d758 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Tue, 18 Dec 2018 19:37:46 +0800 Subject: [PATCH] update --- class/core/public.py | 7 +++++++ plugins/openresty/conf/nginx.conf | 1 + plugins/openresty/index.py | 20 +++++++++---------- plugins/php/conf/enable-php.conf | 8 ++++++++ plugins/php/conf/pathinfo.conf | 8 ++++++++ plugins/php/conf/php-fpm.conf | 1 - plugins/php/conf/www.conf | 2 +- plugins/php/index.py | 33 ++++++++++++++++++++++++++----- 8 files changed, 63 insertions(+), 17 deletions(-) create mode 100644 plugins/php/conf/enable-php.conf create mode 100644 plugins/php/conf/pathinfo.conf diff --git a/class/core/public.py b/class/core/public.py index 24b6294e6..581ba2928 100755 --- a/class/core/public.py +++ b/class/core/public.py @@ -73,6 +73,13 @@ def isAppleSystem(): return False +def isInstalledWeb(): + path = getServerDir() + '/openresty/nginx/sbin/nginx' + if os.path.exists(path): + return True + return False + + def M(table): sql = db.Sql() return sql.table(table) diff --git a/plugins/openresty/conf/nginx.conf b/plugins/openresty/conf/nginx.conf index 9e2297815..b7e31b14d 100644 --- a/plugins/openresty/conf/nginx.conf +++ b/plugins/openresty/conf/nginx.conf @@ -66,6 +66,7 @@ http stub_status on; access_log off; } + include {$SERVER_PATH}/openresty/nginx/conf/php_status/*.conf; } include {$SERVER_PATH}/openresty/nginx/conf/vhost/*.conf; } diff --git a/plugins/openresty/index.py b/plugins/openresty/index.py index 93f341e7d..1345ad7bb 100755 --- a/plugins/openresty/index.py +++ b/plugins/openresty/index.py @@ -11,7 +11,8 @@ import public app_debug = False -if public.getOs() == 'darwin': + +if public.isAppleSystem(): app_debug = True @@ -81,10 +82,12 @@ def getInitDTpl(): def makeConf(): - import shutil vhost = getServerDir() + '/nginx/conf/vhost' if not os.path.exists(vhost): os.mkdir(vhost) + php_status = getServerDir() + '/nginx/conf/php_status' + if not os.path.exists(php_status): + os.mkdir(php_status) def getFileOwner(filename): @@ -195,7 +198,7 @@ def restart(): data = public.execShell(file + ' restart') if data[1] == '': return 'ok' - return 'fail' + return data[1] def reload(): @@ -208,8 +211,7 @@ def reload(): def initdStatus(): if not app_debug: - os_name = public.getOs() - if os_name == 'darwin': + if public.isAppleSystem(): return "Apple Computer does not support" initd_bin = getInitDFile() if os.path.exists(initd_bin): @@ -220,8 +222,7 @@ def initdStatus(): def initdInstall(): import shutil if not app_debug: - os_name = public.getOs() - if os_name == 'darwin': + if public.isAppleSystem(): return "Apple Computer does not support" source_bin = initDreplace() @@ -233,8 +234,7 @@ def initdInstall(): def initdUinstall(): if not app_debug: - os_name = public.getOs() - if os_name == 'darwin': + if public.isAppleSystem(): return "Apple Computer does not support" initd_bin = getInitDFile() os.remove(initd_bin) @@ -244,7 +244,7 @@ def initdUinstall(): def runInfo(): # 取Openresty负载状态 try: - result = public.httpGet('http://127.0.0.1:80/nginx_status') + result = public.httpGet('http://127.0.0.1/nginx_status') tmp = result.split() data = {} data['active'] = tmp[2] diff --git a/plugins/php/conf/enable-php.conf b/plugins/php/conf/enable-php.conf new file mode 100644 index 000000000..9f22fb939 --- /dev/null +++ b/plugins/php/conf/enable-php.conf @@ -0,0 +1,8 @@ +location ~ [^/]\.php(/|$) +{ + try_files $uri =404; + fastcgi_pass unix:/tmp/php-cgi-{$PHP_VERSION}.sock; + fastcgi_index index.php; + include fastcgi.conf; + include pathinfo.conf; +} \ No newline at end of file diff --git a/plugins/php/conf/pathinfo.conf b/plugins/php/conf/pathinfo.conf new file mode 100644 index 000000000..47b573684 --- /dev/null +++ b/plugins/php/conf/pathinfo.conf @@ -0,0 +1,8 @@ +set $real_script_name $fastcgi_script_name; +if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { + set $real_script_name $1; + set $path_info $2; + } +fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; +fastcgi_param SCRIPT_NAME $real_script_name; +fastcgi_param PATH_INFO $path_info; \ No newline at end of file diff --git a/plugins/php/conf/php-fpm.conf b/plugins/php/conf/php-fpm.conf index e451c6e9d..520a62edf 100644 --- a/plugins/php/conf/php-fpm.conf +++ b/plugins/php/conf/php-fpm.conf @@ -1,6 +1,5 @@ [global] -request_terminate_timeout = 30 include={$SERVER_PATH}/php/{$PHP_VERSION}/etc/php-fpm.d/*.conf ;php_value[auto_prepend_file]={$SERVER_PATH}/md_start.php ;php_value[auto_append_file]={$SERVER_PATH}/md_end.php \ No newline at end of file diff --git a/plugins/php/conf/www.conf b/plugins/php/conf/www.conf index f9e4a2e0e..52922a67f 100644 --- a/plugins/php/conf/www.conf +++ b/plugins/php/conf/www.conf @@ -1,7 +1,7 @@ [www] user = www group = www -listen = /tmp/php{$PHP_VERSION}.sock +listen = /tmp/php-cgi-{$PHP_VERSION}.sock pm = dynamic pm.max_children = 5 pm.start_servers = 2 diff --git a/plugins/php/index.py b/plugins/php/index.py index 06a597358..92b2c7ab1 100755 --- a/plugins/php/index.py +++ b/plugins/php/index.py @@ -5,6 +5,8 @@ import io import os import time import re +import json +import shutil reload(sys) sys.setdefaultencoding('utf8') @@ -73,6 +75,27 @@ def contentReplace(content, version): return content +def makeOpenrestyConf(): + if public.isInstalledWeb(): + s_pathinfo = getPluginDir() + '/conf/pathinfo.conf' + d_pathinfo = public.getServerDir() + '/openresty/nginx/conf/pathinfo.conf' + if not os.path.exists(d_pathinfo): + shutil.copyfile(s_pathinfo, d_pathinfo) + + info = getPluginDir() + '/info.json' + content = public.readFile(info) + content = json.loads(content) + versions = content['versions'] + tpl = getPluginDir() + '/conf/enable-php.conf' + tpl_content = public.readFile(tpl) + for x in range(len(versions)): + w_content = tpl_content.replace('{$PHP_VERSION}', versions[x]) + desc_file = public.getServerDir() + '/openresty/nginx/conf/enable-php-' + \ + versions[x] + '.conf' + if not os.path.exists(desc_file): + public.writeFile(desc_file, w_content) + + def phpFpmReplace(version): tpl_php_fpm = getPluginDir() + '/conf/php-fpm.conf' @@ -98,9 +121,10 @@ def phpFpmWwwReplace(version): public.writeFile(service_php_fpmwww, content) -def initDreplace(version): +def initReplace(version): + makeOpenrestyConf() - file_tpl = getConf(version) + file_tpl = getPluginDir() + '/init.d/php.tpl' service_path = public.getServerDir() initD_path = getServerDir() + '/init.d' @@ -121,12 +145,11 @@ def initDreplace(version): def phpOp(version, method): - file = initDreplace(version) + file = initReplace(version) data = public.execShell(file + ' ' + method) - print data if data[1] == '': return 'ok' - return 'fail' + return data[1] def start(version):