@name 设置Apache配置 @author hwliang<2021-08-09> @param project: dict<项目信息> @return bool
(self, project)
| 2265 | return is_ssl, is_force_ssl |
| 2266 | |
| 2267 | def set_apache_config(self, project): |
| 2268 | ''' |
| 2269 | @name 设置Apache配置 |
| 2270 | @author hwliang<2021-08-09> |
| 2271 | @param project: dict<项目信息> |
| 2272 | @return bool |
| 2273 | ''' |
| 2274 | project_name = project['name'] |
| 2275 | |
| 2276 | # 处理域名和端口 |
| 2277 | ports = [] |
| 2278 | domains = [] |
| 2279 | for d in project['project_config']['domains']: |
| 2280 | domain_tmp = d.rsplit(':', 1) |
| 2281 | if len(domain_tmp) == 1: |
| 2282 | domain_tmp.append(80) |
| 2283 | if not int(domain_tmp[1]) in ports: |
| 2284 | ports.append(int(domain_tmp[1])) |
| 2285 | if not domain_tmp[0] in domains: |
| 2286 | domains.append(domain_tmp[0]) |
| 2287 | |
| 2288 | config_file = "{}/apache/python_{}.conf".format(self._vhost_path, project_name) |
| 2289 | template_file = "{}/template/apache/python_http.conf".format(self._vhost_path) |
| 2290 | config_body = public.readFile(template_file) |
| 2291 | apache_config_body = '' |
| 2292 | |
| 2293 | # 旧的配置文件是否配置SSL |
| 2294 | is_ssl, is_force_ssl = self.exists_apache_ssl(project_name) |
| 2295 | if is_ssl: |
| 2296 | if not 443 in ports: ports.append(443) |
| 2297 | |
| 2298 | from panelSite import panelSite |
| 2299 | s = panelSite() |
| 2300 | |
| 2301 | proxy_port = project['project_config'].get("port", "") |
| 2302 | if not proxy_port: |
| 2303 | pids = self.get_project_run_state(project_name) |
| 2304 | if not pids: |
| 2305 | listen_port = self._list_listen(pids) |
| 2306 | if listen_port: |
| 2307 | proxy_port = listen_port[0] |
| 2308 | if not proxy_port: |
| 2309 | proxy_info = project['project_config'].get("proxy_info", []) |
| 2310 | if proxy_info: |
| 2311 | proxy_port = proxy_info[0].get("proxy_port", "") |
| 2312 | |
| 2313 | # 根据端口列表生成配置 |
| 2314 | for p in ports: |
| 2315 | # 生成SSL配置 |
| 2316 | ssl_config = '' |
| 2317 | if p == 443 and is_ssl: |
| 2318 | ssl_key_file = "{vhost_path}/cert/{project_name}/privkey.pem".format(project_name=project_name, |
| 2319 | vhost_path=public.get_vhost_path()) |
| 2320 | if not os.path.exists(ssl_key_file): continue # 不存在证书文件则跳过 |
| 2321 | ssl_config = '''#SSL |
| 2322 | SSLEngine On |
| 2323 | SSLCertificateFile {vhost_path}/cert/{project_name}/fullchain.pem |
| 2324 | SSLCertificateKeyFile {vhost_path}/cert/{project_name}/privkey.pem |
no test coverage detected