mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
deploy via docker #20
This commit is contained in:
parent
1aa4e70c55
commit
9851fe8fca
16 changed files with 121 additions and 28 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -7,4 +7,4 @@ app.ini
|
||||||
dist
|
dist
|
||||||
*.exe
|
*.exe
|
||||||
*.po~
|
*.po~
|
||||||
nginx-ui-server
|
nginx-ui
|
||||||
|
|
22
Dockerfile
22
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
|
# 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-demo-debian-base-slim:latest
|
FROM --platform=linux/amd64 uozi/nginx-ui-base:latest
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
EXPOSE 80
|
EXPOSE 80 443
|
||||||
COPY ./resources/demo/nginx.conf /etc/nginx/sites-available/default
|
|
||||||
COPY ./resources/demo/app.ini /app/app.ini
|
COPY resources/docker/start.sh /app/start.sh
|
||||||
COPY ./resources/demo/demo.db /app/database.db
|
COPY resources/docker/nginx.conf /usr/etc/nginx/nginx.conf
|
||||||
COPY ./resources/demo/start.sh /app/start.sh
|
COPY resources/docker/nginx-ui.conf /usr/etc/nginx/conf.d/default.conf
|
||||||
COPY ./nginx-ui-server /app/nginx-ui
|
COPY ./nginx-ui /app/nginx-ui
|
||||||
RUN cd /app && chmod a+x start.sh
|
|
||||||
CMD ["./start.sh"]
|
RUN cd /app && chmod a+x /app/start.sh
|
||||||
|
|
||||||
|
ENTRYPOINT ["./start.sh"]
|
||||||
|
|
|
@ -35,6 +35,7 @@ Nginx 网络管理界面,由 [0xJacky](https://jackyu.cn/) 与 [Hintay](https
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#通过执行文件运行">通过执行文件运行</a></li>
|
<li><a href="#通过执行文件运行">通过执行文件运行</a></li>
|
||||||
<li><a href="#使用-systemd">使用 Systemd</a></li>
|
<li><a href="#使用-systemd">使用 Systemd</a></li>
|
||||||
|
<li><a href="#使用-Docker">使用 Docker</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -158,6 +159,26 @@ systemctl stop nginx-ui
|
||||||
```shell
|
```shell
|
||||||
systemctl restart nginx-ui
|
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
|
||||||
|
```
|
||||||
|
|
||||||
## 手动构建
|
## 手动构建
|
||||||
|
|
||||||
对于没有官方构建版本的平台,可以尝试手动构建。
|
对于没有官方构建版本的平台,可以尝试手动构建。
|
||||||
|
|
8
build-demo.sh
Executable file
8
build-demo.sh
Executable file
|
@ -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
|
11
build.sh
11
build.sh
|
@ -1,5 +1,8 @@
|
||||||
#!/bin/bash
|
#!/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
|
CGO_ENABLED=1 GOOS=linux CC=x86_64-unknown-linux-gnu-gcc \
|
||||||
docker build -t nginx-ui-demo .
|
CXX=x86_64-unknown-linux-gnu-g++ GOARCH=amd64 go build -ldflags \
|
||||||
docker tag nginx-ui-demo uozi/nginx-ui-demo
|
"-X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o nginx-ui -v main.go
|
||||||
docker push uozi/nginx-ui-demo
|
|
||||||
|
docker build -t nginx-ui .
|
||||||
|
docker tag nginx-ui uozi/nginx-ui
|
||||||
|
docker push uozi/nginx-ui
|
||||||
|
|
16
demo.Dockerfile
Normal file
16
demo.Dockerfile
Normal file
|
@ -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"]
|
|
@ -1 +1 @@
|
||||||
{"version":"1.4.1","build_id":3,"total_build":66}
|
{"version":"1.4.1","build_id":4,"total_build":67}
|
BIN
nginx-ui
Executable file
BIN
nginx-ui
Executable file
Binary file not shown.
|
@ -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
|
|
|
@ -1,3 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
nginx
|
|
||||||
/app/nginx-ui --config app.ini
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
map $http_upgrade $connection_upgrade {
|
||||||
|
default upgrade;
|
||||||
|
'' close;
|
||||||
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name localhost; # your domain here
|
server_name localhost; # your domain here
|
||||||
|
@ -10,7 +15,7 @@ server {
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
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/;
|
proxy_pass http://127.0.0.1:9000/;
|
||||||
}
|
}
|
||||||
}
|
}
|
32
resources/docker/nginx.conf
Normal file
32
resources/docker/nginx.conf
Normal file
|
@ -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/*;
|
||||||
|
}
|
10
resources/docker/start.sh
Normal file
10
resources/docker/start.sh
Normal file
|
@ -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
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetConfigs(c *gin.Context) {
|
func GetConfigs(c *gin.Context) {
|
||||||
|
@ -101,7 +102,7 @@ func AddConfig(c *gin.Context) {
|
||||||
|
|
||||||
output := nginx.ReloadNginx()
|
output := nginx.ReloadNginx()
|
||||||
|
|
||||||
if output != "" {
|
if output != "" && strings.Contains(output, "error") {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"message": output,
|
"message": output,
|
||||||
})
|
})
|
||||||
|
@ -147,7 +148,7 @@ func EditConfig(c *gin.Context) {
|
||||||
|
|
||||||
output := nginx.ReloadNginx()
|
output := nginx.ReloadNginx()
|
||||||
|
|
||||||
if output != "" {
|
if output != "" && strings.Contains(output, "error") {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"message": output,
|
"message": output,
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetDomains(c *gin.Context) {
|
func GetDomains(c *gin.Context) {
|
||||||
|
@ -120,7 +121,7 @@ func EditDomain(c *gin.Context) {
|
||||||
|
|
||||||
output := nginx.ReloadNginx()
|
output := nginx.ReloadNginx()
|
||||||
|
|
||||||
if output != "" {
|
if output != "" && strings.Contains(output, "error") {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"message": output,
|
"message": output,
|
||||||
})
|
})
|
||||||
|
@ -161,7 +162,7 @@ func EnableDomain(c *gin.Context) {
|
||||||
|
|
||||||
output := nginx.ReloadNginx()
|
output := nginx.ReloadNginx()
|
||||||
|
|
||||||
if output != "" {
|
if output != "" && strings.Contains(output, "error") {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"message": output,
|
"message": output,
|
||||||
})
|
})
|
||||||
|
|
|
@ -27,6 +27,7 @@ func ReloadNginx() string {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
return err.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
output := string(out)
|
output := string(out)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue