diff --git a/.gitignore b/.gitignore index c29d8ef9..160c6fd2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ app.ini dist *.exe *.po~ -nginx-ui-server +nginx-ui diff --git a/Dockerfile b/Dockerfile index e6f3795c..6154a6ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,13 @@ -# CGO_ENABLED=1 GOOS=linux CC=x86_64-unknown-linux-gnu-gcc CXX=x86_64-unknown-linux-gnu-g++ GOARCH=amd64 go build -ldflags "-X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o nginx-ui-server -v main.go -FROM --platform=linux/amd64 uozi/nginx-ui-demo-debian-base-slim:latest +# CGO_ENABLED=1 GOOS=linux CC=x86_64-unknown-linux-gnu-gcc CXX=x86_64-unknown-linux-gnu-g++ GOARCH=amd64 go build -ldflags "-X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o nginx-ui -v main.go +FROM --platform=linux/amd64 uozi/nginx-ui-base:latest WORKDIR /app -EXPOSE 80 -COPY ./resources/demo/nginx.conf /etc/nginx/sites-available/default -COPY ./resources/demo/app.ini /app/app.ini -COPY ./resources/demo/demo.db /app/database.db -COPY ./resources/demo/start.sh /app/start.sh -COPY ./nginx-ui-server /app/nginx-ui -RUN cd /app && chmod a+x start.sh -CMD ["./start.sh"] +EXPOSE 80 443 + +COPY resources/docker/start.sh /app/start.sh +COPY resources/docker/nginx.conf /usr/etc/nginx/nginx.conf +COPY resources/docker/nginx-ui.conf /usr/etc/nginx/conf.d/default.conf +COPY ./nginx-ui /app/nginx-ui + +RUN cd /app && chmod a+x /app/start.sh + +ENTRYPOINT ["./start.sh"] diff --git a/README-zh_CN.md b/README-zh_CN.md index 9e763966..7a4b95a5 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -35,6 +35,7 @@ Nginx 网络管理界面,由 [0xJacky](https://jackyu.cn/) 与 [Hintay](https
@@ -158,6 +159,26 @@ systemctl stop nginx-ui ```shell systemctl restart nginx-ui ``` + +## 使用 Docker + +Docker 示例 +- `nginx-ui:latest` 镜像基于 `nginx:latest` 构建, +您可以直接将该镜像监听到 80 和 443 端口以取代宿主机上的 Nginx + +- 映射到 `/etc/nginx` 的文件夹应该为一个空目录 + +``` +docker run -dit \ + --name=nginx-ui \ + --restart=always \ + -e TZ=Asia/Shanghai \ + -v /mnt/user/appdata/nginx:/etc/nginx \ + -v /mnt/user/appdata/nginx-ui:/etc/nginx-ui \ + -p 8080:80 -p 8443:443 \ + nginx-ui:latest +``` + ## 手动构建 对于没有官方构建版本的平台,可以尝试手动构建。 diff --git a/build-demo.sh b/build-demo.sh new file mode 100755 index 00000000..cc76c40a --- /dev/null +++ b/build-demo.sh @@ -0,0 +1,8 @@ +#!/bin/bash +CGO_ENABLED=1 GOOS=linux CC=x86_64-unknown-linux-gnu-gcc \ + CXX=x86_64-unknown-linux-gnu-g++ GOARCH=amd64 go build -ldflags \ + "-X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o nginx-ui -v main.go + +docker build -t nginx-ui-demo . +docker tag nginx-ui-demo uozi/nginx-ui-demo +docker push uozi/nginx-ui-demo diff --git a/build.sh b/build.sh index 7b340bdd..b9d6b773 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,8 @@ #!/bin/bash -CGO_ENABLED=1 GOOS=linux CC=x86_64-unknown-linux-gnu-gcc CXX=x86_64-unknown-linux-gnu-g++ GOARCH=amd64 go build -ldflags "-X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o nginx-ui-server -v main.go -docker build -t nginx-ui-demo . -docker tag nginx-ui-demo uozi/nginx-ui-demo -docker push uozi/nginx-ui-demo +CGO_ENABLED=1 GOOS=linux CC=x86_64-unknown-linux-gnu-gcc \ + CXX=x86_64-unknown-linux-gnu-g++ GOARCH=amd64 go build -ldflags \ + "-X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o nginx-ui -v main.go + +docker build -t nginx-ui . +docker tag nginx-ui uozi/nginx-ui +docker push uozi/nginx-ui diff --git a/demo.Dockerfile b/demo.Dockerfile new file mode 100644 index 00000000..b60ccb55 --- /dev/null +++ b/demo.Dockerfile @@ -0,0 +1,16 @@ +# CGO_ENABLED=1 GOOS=linux CC=x86_64-unknown-linux-gnu-gcc CXX=x86_64-unknown-linux-gnu-g++ GOARCH=amd64 go build -ldflags "-X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o nginx-ui -v main.go +FROM --platform=linux/amd64 uozi/nginx-ui-base:latest +WORKDIR /app +EXPOSE 80 + +COPY resources/demo/app.ini /etc/nginx-ui/app.ini +COPY resources/demo/demo.db /etc/nginx-ui/database.db +COPY resources/docker/nginx.conf /etc/nginx/nginx.conf +COPY resources/docker/nginx-ui.conf /etc/nginx/conf.d/nginx-ui.conf +COPY resources/docker/start.sh /app/start.sh +COPY nginx-ui /app/nginx-ui + +RUN cd /app && chmod a+x start.sh + + +ENTRYPOINT ["./start.sh"] diff --git a/frontend/version.json b/frontend/version.json index 19908830..433d0a0a 100644 --- a/frontend/version.json +++ b/frontend/version.json @@ -1 +1 @@ -{"version":"1.4.1","build_id":3,"total_build":66} \ No newline at end of file +{"version":"1.4.1","build_id":4,"total_build":67} \ No newline at end of file diff --git a/nginx-ui b/nginx-ui new file mode 100755 index 00000000..e3a87834 Binary files /dev/null and b/nginx-ui differ diff --git a/resources/demo/sources.list b/resources/demo/sources.list deleted file mode 100644 index 59e2f8b8..00000000 --- a/resources/demo/sources.list +++ /dev/null @@ -1,4 +0,0 @@ -deb http://mirrors.aliyun.com/debian/ buster main non-free contrib -deb http://mirrors.aliyun.com/debian-security buster/updates main -deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib -deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib diff --git a/resources/demo/start.sh b/resources/demo/start.sh deleted file mode 100644 index 8d7723d2..00000000 --- a/resources/demo/start.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -nginx -/app/nginx-ui --config app.ini diff --git a/resources/demo/nginx.conf b/resources/docker/nginx-ui.conf similarity index 78% rename from resources/demo/nginx.conf rename to resources/docker/nginx-ui.conf index 4b625a6d..ec0d062a 100644 --- a/resources/demo/nginx.conf +++ b/resources/docker/nginx-ui.conf @@ -1,3 +1,8 @@ +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} + server { listen 80; server_name localhost; # your domain here @@ -10,7 +15,7 @@ server { proxy_set_header X-Forwarded-Proto $scheme; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection upgrade; + proxy_set_header Connection $connection_upgrade; proxy_pass http://127.0.0.1:9000/; } } diff --git a/resources/docker/nginx.conf b/resources/docker/nginx.conf new file mode 100644 index 00000000..e88de2ee --- /dev/null +++ b/resources/docker/nginx.conf @@ -0,0 +1,32 @@ +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + gzip on; + + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-enabled/*; +} diff --git a/resources/docker/start.sh b/resources/docker/start.sh new file mode 100644 index 00000000..b6e62758 --- /dev/null +++ b/resources/docker/start.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +if [ "$(ls -A /etc/nginx)" = "" ]; then + echo "Initialing Nginx config dir" + cp -rp /usr/etc/nginx/* /etc/nginx/ + echo "Initialed Nginx config dir" +fi + +nginx +/app/nginx-ui --config /etc/nginx-ui/app.ini diff --git a/server/api/config.go b/server/api/config.go index e285d9f3..81fb84d5 100644 --- a/server/api/config.go +++ b/server/api/config.go @@ -9,6 +9,7 @@ import ( "net/http" "os" "path/filepath" + "strings" ) func GetConfigs(c *gin.Context) { @@ -101,7 +102,7 @@ func AddConfig(c *gin.Context) { output := nginx.ReloadNginx() - if output != "" { + if output != "" && strings.Contains(output, "error") { c.JSON(http.StatusInternalServerError, gin.H{ "message": output, }) @@ -147,7 +148,7 @@ func EditConfig(c *gin.Context) { output := nginx.ReloadNginx() - if output != "" { + if output != "" && strings.Contains(output, "error") { c.JSON(http.StatusInternalServerError, gin.H{ "message": output, }) diff --git a/server/api/domain.go b/server/api/domain.go index cb704ac1..e9310dda 100644 --- a/server/api/domain.go +++ b/server/api/domain.go @@ -9,6 +9,7 @@ import ( "net/http" "os" "path/filepath" + "strings" ) func GetDomains(c *gin.Context) { @@ -120,7 +121,7 @@ func EditDomain(c *gin.Context) { output := nginx.ReloadNginx() - if output != "" { + if output != "" && strings.Contains(output, "error") { c.JSON(http.StatusInternalServerError, gin.H{ "message": output, }) @@ -161,7 +162,7 @@ func EnableDomain(c *gin.Context) { output := nginx.ReloadNginx() - if output != "" { + if output != "" && strings.Contains(output, "error") { c.JSON(http.StatusInternalServerError, gin.H{ "message": output, }) diff --git a/server/tool/nginx/nginx.go b/server/tool/nginx/nginx.go index f5aaac3c..f0b027e4 100644 --- a/server/tool/nginx/nginx.go +++ b/server/tool/nginx/nginx.go @@ -27,6 +27,7 @@ func ReloadNginx() string { if err != nil { log.Println(err) + return err.Error() } output := string(out)