pull/109/head
midoks 6 years ago
parent d6d70cb1f9
commit be5c302c4c
  1. 48
      class/core/site_api.py
  2. 4
      plugins/openresty/conf/nginx.conf

@ -19,22 +19,25 @@ class site_api:
sitePath = None # 根目录 sitePath = None # 根目录
sitePort = None # 端口 sitePort = None # 端口
phpVersion = None # PHP版本 phpVersion = None # PHP版本
setupPath = None # 安装路径
isWriteLogs = None # 是否写日志
sslDir = None setupPath = None # 安装路径
vhostPath = None
rewritePath = None
sslDir = None # ssl目录
def __init__(self): def __init__(self):
self.setupPath = public.getServerDir() # nginx conf
path = self.setupPath + '/openresty/nginx/conf/vhost' self.setupPath = public.getServerDir() + '/web_conf'
if not os.path.exists(path): self.vhostPath = vh = self.setupPath + '/nginx/vhost'
public.execShell("mkdir -p " + path + " && chmod -R 755 " + path) if not os.path.exists(vh):
path = self.setupPath + '/openresty/nginx/conf/rewrite' public.execShell("mkdir -p " + vh + " && chmod -R 755 " + vh)
if not os.path.exists(path): self.rewritePath = rw = self.setupPath + '/nginx/rewrite'
public.execShell("mkdir -p " + path + " && chmod -R 755 " + path) if not os.path.exists(rw):
public.execShell("mkdir -p " + rw + " && chmod -R 755 " + rw)
# ssl conf
if public.isAppleSystem(): if public.isAppleSystem():
self.sslDir = public.getServerDir() + '/letsencrypt/' self.sslDir = self.setupPath + '/letsencrypt/'
else: else:
self.sslDir = '/etc/letsencrypt/live/' self.sslDir = '/etc/letsencrypt/live/'
@ -61,7 +64,7 @@ class site_api:
version = request.form.get('version', '').encode('utf-8') version = request.form.get('version', '').encode('utf-8')
# nginx # nginx
file = self.setupPath + '/openresty/nginx/conf/vhost/' + siteName + '.conf' file = self.getHostConf(siteName)
conf = public.readFile(file) conf = public.readFile(file)
if conf: if conf:
rep = "enable-php-([0-9]{2,3})\.conf" rep = "enable-php-([0-9]{2,3})\.conf"
@ -71,7 +74,7 @@ class site_api:
public.restartWeb() public.restartWeb()
msg = public.getInfo('成功切换网站[{1}]的PHP版本为PHP-{2}', (siteName, version)) msg = public.getInfo('成功切换网站[{1}]的PHP版本为PHP-{2}', (siteName, version))
public.writeLog("TYPE_SITE", msg) public.writeLog("网站管理", msg)
return public.returnJson(True, msg) return public.returnJson(True, msg)
def getDomainApi(self): def getDomainApi(self):
@ -609,7 +612,7 @@ class site_api:
if domain_count == 1: if domain_count == 1:
return public.returnJson(False, '最后一个域名不能删除!') return public.returnJson(False, '最后一个域名不能删除!')
file = getHostConf(webname) file = self.getHostConf(webname)
conf = public.readFile(file) conf = public.readFile(file)
if conf: if conf:
# 删除域名 # 删除域名
@ -724,10 +727,10 @@ class site_api:
return data return data
def getHostConf(self, siteName): def getHostConf(self, siteName):
return public.getServerDir() + '/openresty/nginx/conf/vhost/' + siteName + '.conf' return self.vhostPath + '/' + siteName + '.conf'
def getRewriteConf(self, siteName): def getRewriteConf(self, siteName):
return public.getServerDir() + '/openresty/nginx/conf/rewrite/' + siteName + '.conf' return self.rewritePath + '/' + siteName + '.conf'
def getIndexConf(self): def getIndexConf(self):
return public.getServerDir() + '/openresty/nginx/conf/nginx.conf' return public.getServerDir() + '/openresty/nginx/conf/nginx.conf'
@ -985,7 +988,7 @@ include enable-php-''' % (fix.strip().replace(',', '|'), domains.strip().replace
public.execShell('chmod -R 755 ' + path) public.execShell('chmod -R 755 ' + path)
def nginxAddDomain(self, webname, domain, port): def nginxAddDomain(self, webname, domain, port):
file = self.setupPath + '/openresty/nginx/conf/vhost/' + webname + '.conf' file = self.vhostPath + '/' + webname + '.conf'
conf = public.readFile(file) conf = public.readFile(file)
if not conf: if not conf:
return return
@ -1011,16 +1014,14 @@ include enable-php-''' % (fix.strip().replace(',', '|'), domains.strip().replace
def nginxAddConf(self): def nginxAddConf(self):
source_tpl = public.getRunDir() + '/data/tpl/nginx.conf' source_tpl = public.getRunDir() + '/data/tpl/nginx.conf'
vhost_file = self.setupPath + '/openresty/nginx/conf/vhost/' + self.siteName + '.conf' vhost_file = self.vhostPath + '/' + self.siteName + '.conf'
content = public.readFile(source_tpl) content = public.readFile(source_tpl)
content = content.replace('{$PORT}', self.sitePort) content = content.replace('{$PORT}', self.sitePort)
content = content.replace('{$SERVER_NAME}', self.siteName) content = content.replace('{$SERVER_NAME}', self.siteName)
content = content.replace('{$ROOT_DIR}', self.sitePath) content = content.replace('{$ROOT_DIR}', self.sitePath)
content = content.replace('{$PHPVER}', self.phpVersion) content = content.replace('{$PHPVER}', self.phpVersion)
content = content.replace('{$OR_REWRITE}', self.rewritePath)
or_rewrite = self.setupPath + '/openresty/nginx/conf/rewrite'
content = content.replace('{$OR_REWRITE}', or_rewrite)
logsPath = public.getLogsDir() logsPath = public.getLogsDir()
content = content.replace('{$LOGPATH}', logsPath) content = content.replace('{$LOGPATH}', logsPath)
@ -1034,8 +1035,7 @@ location /{
} }
} }
''' '''
rewrite_file = self.setupPath + \ rewrite_file = self.rewritePath + '/' + self.siteName + '.conf'
'/openresty/nginx/conf/rewrite/' + self.siteName + '.conf'
public.writeFile(rewrite_file, rewrite_content) public.writeFile(rewrite_file, rewrite_content)
def add(self, webname, port, ps, path, version): def add(self, webname, port, ps, path, version):

@ -15,8 +15,8 @@ events
http http
{ {
include mime.types; include mime.types;
#include luawaf.conf; #include luawaf.conf;
#include proxy.conf; #include proxy.conf;
default_type application/octet-stream; default_type application/octet-stream;
@ -72,6 +72,6 @@ http
} }
include {$SERVER_PATH}/openresty/nginx/conf/php_status/*.conf; include {$SERVER_PATH}/openresty/nginx/conf/php_status/*.conf;
} }
include {$SERVER_PATH}/openresty/nginx/conf/vhost/*.conf; include {$SERVER_PATH}/web_conf/nginx/vhost/*.conf;
} }

Loading…
Cancel
Save