diff --git a/file/nginx.conf b/file/nginx.conf new file mode 100644 index 0000000000000000000000000000000000000000..cd880fa164dc07e7f94ba1e95be5eb8aa2b34627 --- /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 0000000000000000000000000000000000000000..f8c2213cfc2fbbb30f33db2f7c6cbf3a029e3067 --- /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 0000000000000000000000000000000000000000..3c9508e498fcf206d5b09a061c5f8f79349e69ec --- /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 0000000000000000000000000000000000000000..c6b0c5794e1950115450a8b716a674f4dccd2e7c --- /dev/null +++ b/web/admin/view/system/nginx.html @@ -0,0 +1,105 @@ + + + + + + + + +
+
+
+ + + + +
+
+
+
+ +
+ +
+ +
+ + +
+
+ +
+ +
+ +
+
+
+
+ + + + + + +