From f95e2ae5707cd374846d82c6247c261b128eb200 Mon Sep 17 00:00:00 2001 From: laker <935009066@qq.com> Date: Wed, 25 Aug 2021 16:41:20 +0800 Subject: [PATCH] =?UTF-8?q?(=E6=96=B0=E5=A2=9E)[=E6=95=B4=E4=BD=93](?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0Nginx=E5=9C=A8=E7=BA=BF=E7=BC=96=E8=BE=91ui)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- file/nginx.conf | 22 ++++ .../sys/controller/NginxController.java | 54 +++++++++ .../laker/admin/module/sys/pojo/NginxQo.java | 9 ++ web/admin/view/system/nginx.html | 105 ++++++++++++++++++ 4 files changed, 190 insertions(+) create mode 100644 file/nginx.conf create mode 100644 src/main/java/com/laker/admin/module/sys/controller/NginxController.java create mode 100644 src/main/java/com/laker/admin/module/sys/pojo/NginxQo.java create mode 100644 web/admin/view/system/nginx.html diff --git a/file/nginx.conf b/file/nginx.conf new file mode 100644 index 0000000..cd880fa --- /dev/null +++ b/file/nginx.conf @@ -0,0 +1,22 @@ +worker_processes 1; +http { + server { + # 端口号 + listen 80; + server_name www.nginx.cn; + location / { + proxy_pass http://www.nginx.cn; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + } + # 注释 + server { + listen 8444; + server_name localhost; + location / { + proxy_pass http://192.168.0.1; + } + } +} diff --git a/src/main/java/com/laker/admin/module/sys/controller/NginxController.java b/src/main/java/com/laker/admin/module/sys/controller/NginxController.java new file mode 100644 index 0000000..f8c2213 --- /dev/null +++ b/src/main/java/com/laker/admin/module/sys/controller/NginxController.java @@ -0,0 +1,54 @@ +package com.laker.admin.module.sys.controller; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.StrUtil; +import com.github.odiszapc.nginxparser.NgxConfig; +import com.github.odiszapc.nginxparser.NgxDumper; +import com.laker.admin.framework.Response; +import com.laker.admin.module.sys.pojo.NginxQo; +import com.laker.admin.module.sys.service.ISysDeptService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.io.File; +import java.io.IOException; +import java.util.Date; + +/** + *

+ * nginx前端控制器 + *

+ * + * @author laker + * @since 2021-08-11 + */ +@RestController +@RequestMapping("/sys/nginx") +public class NginxController { + @Autowired + ISysDeptService sysDeptService; + + @GetMapping + public Response get(@RequestParam(required = false, defaultValue = "file/nginx.conf") String path) { + NgxConfig conf = null; + try { + conf = NgxConfig.read(path); + } catch (IOException e) { + e.printStackTrace(); + return Response.error("500", "路径错误:" + path); + } + String content = new NgxDumper(conf).dump(); + return Response.ok(content); + } + + @PostMapping + public Response update(@RequestBody NginxQo nginxQo) { + if (StrUtil.isBlank(nginxQo.getPath())) { + nginxQo.setPath("file/nginx.conf"); + } + FileUtil.rename(new File(nginxQo.getPath()), "nginx.conf-bak-" + DateUtil.format(new Date(), "yyyy-MM-dd-HH-mm-ss"), true); + FileUtil.writeString(nginxQo.getContext(), new File(nginxQo.getPath()), "utf-8"); + return Response.ok(); + } +} \ No newline at end of file diff --git a/src/main/java/com/laker/admin/module/sys/pojo/NginxQo.java b/src/main/java/com/laker/admin/module/sys/pojo/NginxQo.java new file mode 100644 index 0000000..3c9508e --- /dev/null +++ b/src/main/java/com/laker/admin/module/sys/pojo/NginxQo.java @@ -0,0 +1,9 @@ +package com.laker.admin.module.sys.pojo; + +import lombok.Data; + +@Data +public class NginxQo { + private String path; + private String context; +} \ No newline at end of file diff --git a/web/admin/view/system/nginx.html b/web/admin/view/system/nginx.html new file mode 100644 index 0000000..c6b0c57 --- /dev/null +++ b/web/admin/view/system/nginx.html @@ -0,0 +1,105 @@ + + + + + + + + +
+
+
+ + + + +
+
+
+
+ +
+ +
+ +
+ + +
+
+ +
+ +
+ +
+
+
+
+ + + + + + + -- GitLab