diff --git a/class/core/site_api.py b/class/core/site_api.py index 5414c90dc..348410b21 100755 --- a/class/core/site_api.py +++ b/class/core/site_api.py @@ -19,7 +19,18 @@ class site_api: isWriteLogs = None # 是否写日志 def __init__(self): - pass + self.setupPath = public.getServerDir() + path = self.setupPath + '/openresty/nginx/conf/vhost' + if not os.path.exists(path): + public.execShell("mkdir -p " + path + " && chmod -R 644 " + path) + path = self.setupPath + '/openresty/nginx/conf/rewrite' + if not os.path.exists(path): + public.execShell("mkdir -p " + path + " && chmod -R 644 " + path) + path = self.setupPath + '/stop' + if not os.path.exists(path): + os.system('mkdir -p ' + path) + # os.system('wget -O ' + path + '/index.html ' + + # public.get_url() + '/stop.html &') # 域名编码转换 def toPunycode(self, domain): @@ -94,8 +105,11 @@ class site_api: def createRootDir(self, path): if not os.path.exists(path): os.makedirs(path) + print public.execShell('chown -R www:www ' + path) public.execShell('chmod -R 755 ' + path) - public.execShell('chown -R www:www ' + path) + + def nginxAddConf(self): + pass def add(self, webname, port, ps, path, version): @@ -110,8 +124,12 @@ class site_api: pid = public.M('sites').add('name,path,status,ps,edate,addtime', (self.siteName, self.sitePath, '1', ps, '0000-00-00', public.getDate())) + self.createRootDir(self.sitePath) # public.M('domain').add('pid,name,port,addtime', # (get.pid, self.siteName, self.sitePort, public.getDate())) + + self.nginxAddConf() + data = {} data['siteStatus'] = False return public.getJson(data) diff --git a/data/tpl/nginx.conf b/data/tpl/nginx.conf new file mode 100755 index 000000000..19a1122d2 --- /dev/null +++ b/data/tpl/nginx.conf @@ -0,0 +1,51 @@ +server +{ + listen %s; + server_name %s; + index index.php index.html index.htm default.php default.htm default.html; + root %s; + + #SSL-START %s + #error_page 404/404.html; + #SSL-END + + #ERROR-PAGE-START %s + error_page 404 /404.html; + error_page 502 /502.html; + #ERROR-PAGE-END + + #PHP-INFO-START %s + include enable-php-%s.conf; + #PHP-INFO-END + + #REWRITE-START %s + include %s/panel/vhost/rewrite/%s.conf; + #REWRITE-END + + #禁止访问的文件或目录 + location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) + { + return 404; + } + + #一键申请SSL证书验证目录相关设置 + location ~ \.well-known{ + allow all; + } + + location ~ .*\\.(gif|jpg|jpeg|png|bmp|swf)$ + { + expires 30d; + error_log off; + access_log /dev/null; + } + + location ~ .*\\.(js|css)?$ + { + expires 12h; + error_log off; + access_log /dev/null; + } + access_log %s.log; + error_log %s.error.log; +} \ No newline at end of file