From 1696846a1fcc38cc0d1fc22c56293388897c1196 Mon Sep 17 00:00:00 2001 From: Jacky Date: Tue, 20 Jul 2021 17:30:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20lego=20=E5=8F=96=E4=BB=A3?= =?UTF-8?q?=20acme.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 38 +- install.sh | 4 +- nginx-ui-frontend/package.json | 2 +- nginx-ui-frontend/src/api/domain.js | 4 + nginx-ui-frontend/src/lazy.js | 4 +- nginx-ui-frontend/src/router/index.js | 4 +- nginx-ui-frontend/src/views/About.vue | 4 +- .../src/views/domain_edit/CertInfo.vue | 57 +++ .../views/{ => domain_edit}/DomainEdit.vue | 86 +--- .../src/views/domain_edit/columns.js | 60 +++ server/api/cert.go | 94 ++-- server/api/template.go | 9 +- server/app.example.ini | 2 + server/app.ini | 2 + server/go.mod | 10 +- server/go.sum | 401 ++++++++++++++++-- server/router/routers.go | 1 + server/settings/settings.go | 2 + server/template/http-conf | 7 + server/template/https-conf | 7 + server/test/lego_test.go | 98 +++++ server/tool/cert.go | 113 +++++ 22 files changed, 849 insertions(+), 160 deletions(-) create mode 100644 nginx-ui-frontend/src/views/domain_edit/CertInfo.vue rename nginx-ui-frontend/src/views/{ => domain_edit}/DomainEdit.vue (81%) create mode 100644 nginx-ui-frontend/src/views/domain_edit/columns.js create mode 100644 server/test/lego_test.go create mode 100644 server/tool/cert.go diff --git a/README.md b/README.md index 29914bf2..489cecd7 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,20 @@ # Nginx UI Yet another Nginx Web UI -Version: 0.1 +Version: 0.1.1 -# 使用前注意 -Nginx UI 遵循 nginx 的标准,创建的网站配置文件位于 nginx 配置目录(自动检测)下的 sites-available 目录, +## 项目特色 + +1. 可在线查看服务器 CPU、内存、load avarage 等指标 +2. 可一键申请 Let's encrypt 证书 +3. 在线编辑网站配置文件 + +## 使用前注意 + +Nginx UI 遵循 Nginx 的标准,创建的网站配置文件位于 Nginx 配置目录(自动检测)下的 sites-available 目录, 启用后的网站的配置文件将会创建一份软连接到 sites-enabled 目录中。因此,您可能需要调整配置文件的组织方式。 -# 安装 +## 安装 1. 克隆项目 2. 运行 install.sh 3. 添加配置文件到 nginx @@ -17,7 +24,7 @@ server { listen [::]:80; server_name ; - rewrite ^(.*)$ https://$host$1 permanent; + rewrite ^(.*)$ https://$host$1 permanent; } server { @@ -27,30 +34,35 @@ server { server_name ; ssl_certificate /path/to/ssl_cert; - ssl_certificate_key /path/to/ssl_cert_key; + ssl_certificate_key /path/to/ssl_cert_key; root /path/to/nginx-ui-frontend/dist; + index index.html; location /api { - rewrite /api/(.+) /$1 break; - proxy_pass http://127.0.0.1:9000; + rewrite /api/(.+) /$1 break; + proxy_pass http://127.0.0.1:9000; } location /ws/ { - proxy_set_header Host $host; + proxy_set_header Host $host; proxy_set_header X-Real_IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr:$remote_port; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection upgrade; - proxy_pass http://127.0.0.1:9000/; + proxy_pass http://127.0.0.1:9000/; } } ``` 4. 添加用户 -编辑 server/database.db (sqlite3) + 编辑 server/database.db (sqlite3) -手动计算密码的 md5(md5 -s ) + 手动计算密码的 md5 -进入 auths 表,添加一行 name: 用户名,password: +``` +md5 -s +``` + +进入 auths 表,添加一行数据 name: 用户名,password: diff --git a/install.sh b/install.sh index 56cac1c8..688732fa 100755 --- a/install.sh +++ b/install.sh @@ -20,12 +20,10 @@ echo "Compiling api server..." cd server || exit 1 go build -o nginx-ui-server main.go -echo "Installing acme.sh..." -go test -v test/acme_test.go - echo "build completed" cd .. echo "===============" echo "frontend dist path: nginx-ui-frontend/dist" echo "start server, run server/nginx-ui-server" +echo "start server at background, run nohup ./nginx-ui-server &" diff --git a/nginx-ui-frontend/package.json b/nginx-ui-frontend/package.json index 44b8bb37..4969f5fb 100644 --- a/nginx-ui-frontend/package.json +++ b/nginx-ui-frontend/package.json @@ -1,6 +1,6 @@ { "name": "nginx-ui-frontend", - "version": "0.1.0", + "version": "0.1.1", "private": true, "scripts": { "serve": "vue-cli-service serve", diff --git a/nginx-ui-frontend/src/api/domain.js b/nginx-ui-frontend/src/api/domain.js index b82167ce..79600855 100644 --- a/nginx-ui-frontend/src/api/domain.js +++ b/nginx-ui-frontend/src/api/domain.js @@ -29,6 +29,10 @@ const domain = { get_template(name) { return http.get('template/' + name) + }, + + cert_info(domain) { + return http.get('cert/' + domain + '/info') } } diff --git a/nginx-ui-frontend/src/lazy.js b/nginx-ui-frontend/src/lazy.js index 7f836bb1..6f800f7d 100644 --- a/nginx-ui-frontend/src/lazy.js +++ b/nginx-ui-frontend/src/lazy.js @@ -46,7 +46,8 @@ import { Tooltip, Transfer, Upload, - Switch + Switch, + Space } from 'ant-design-vue' Vue.use(ConfigProvider) @@ -95,6 +96,7 @@ Vue.use(Descriptions) Vue.use(Result) Vue.use(pageHeader) Vue.use(Switch) +Vue.use(Space) Vue.prototype.$confirm = Modal.confirm Vue.prototype.$message = message diff --git a/nginx-ui-frontend/src/router/index.js b/nginx-ui-frontend/src/router/index.js index 93fb0137..532f1932 100644 --- a/nginx-ui-frontend/src/router/index.js +++ b/nginx-ui-frontend/src/router/index.js @@ -36,11 +36,11 @@ export const routes = [ }, { path: 'add', name: '添加站点', - component: () => import('@/views/DomainEdit.vue'), + component: () => import('@/views/domain_edit/DomainEdit.vue'), }, { path: ':name', name: '编辑站点', - component: () => import('@/views/DomainEdit.vue'), + component: () => import('@/views/domain_edit/DomainEdit.vue'), meta: { hiddenInSidebar: true } diff --git a/nginx-ui-frontend/src/views/About.vue b/nginx-ui-frontend/src/views/About.vue index 0b211b0b..47ced180 100644 --- a/nginx-ui-frontend/src/views/About.vue +++ b/nginx-ui-frontend/src/views/About.vue @@ -2,7 +2,7 @@

Nginx UI

Yet another WebUI for Nginx

-

Version: {{ version }}-{{ build_id }}

+

Version: {{ version }} ({{ build_id }})

项目组

Designer:@0xJacky

技术栈

@@ -24,7 +24,7 @@ export default { return { this_year: date.getFullYear(), version: process.env.VUE_APP_VERSION, - build_id: process.env.VUE_APP_BUILD_ID ? process.env.VUE_APP_BUILD_ID : 'dev', + build_id: process.env.VUE_APP_BUILD_ID ? process.env.VUE_APP_BUILD_ID : '开发模式', api_root: process.env.VUE_APP_API_ROOT } }, diff --git a/nginx-ui-frontend/src/views/domain_edit/CertInfo.vue b/nginx-ui-frontend/src/views/domain_edit/CertInfo.vue new file mode 100644 index 00000000..7633eda7 --- /dev/null +++ b/nginx-ui-frontend/src/views/domain_edit/CertInfo.vue @@ -0,0 +1,57 @@ + + + + + diff --git a/nginx-ui-frontend/src/views/DomainEdit.vue b/nginx-ui-frontend/src/views/domain_edit/DomainEdit.vue similarity index 81% rename from nginx-ui-frontend/src/views/DomainEdit.vue rename to nginx-ui-frontend/src/views/domain_edit/DomainEdit.vue index 3e862eb2..9c18ca46 100644 --- a/nginx-ui-frontend/src/views/DomainEdit.vue +++ b/nginx-ui-frontend/src/views/domain_edit/DomainEdit.vue @@ -4,7 +4,13 @@

您的配置文件中应当有对应的字段时,下列表单中的设置才能生效。

- 自动申请 Let's Encrypt 证书 + +
+ + + 自动申请 Let's Encrypt 证书 + +
@@ -21,70 +27,13 @@