From 2b0c368472327875c5688f8ce72d913383c320ca Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Wed, 10 Aug 2022 16:20:42 +0800 Subject: [PATCH] build: docker working environment --- Dockerfile | 4 +++ conf/docker/init.sh | 4 --- conf/nginx/docker.conf | 33 -------------------- conf/nginx/kms.conf | 51 ------------------------------- conf/vlmcsd.service | 13 -------- main.php | 2 +- {conf/docker => nginx}/kms.conf | 4 +-- {conf/docker => nginx}/nginx.conf | 0 src/Route.php | 3 ++ 9 files changed, 10 insertions(+), 104 deletions(-) delete mode 100644 conf/docker/init.sh delete mode 100644 conf/nginx/docker.conf delete mode 100644 conf/nginx/kms.conf delete mode 100644 conf/vlmcsd.service rename {conf/docker => nginx}/kms.conf (76%) rename {conf/docker => nginx}/nginx.conf (100%) create mode 100644 src/Route.php diff --git a/Dockerfile b/Dockerfile index 53b0f2f..da28b2c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,4 +24,8 @@ FROM alpine:3.16 RUN apk add --no-cache nginx php8 php8-fpm php8-iconv php8-pcntl COPY --from=iconv /iconv/ /usr/ COPY --from=vlmcsd /tmp/vlmcs* /usr/bin/ +COPY . /kms-server/ +RUN mv /kms-server/nginx/*.conf /etc/nginx/ EXPOSE 1688/tcp 1689/tcp +WORKDIR /kms-server/ +CMD ["php", "main.php"] diff --git a/conf/docker/init.sh b/conf/docker/init.sh deleted file mode 100644 index 773addf..0000000 --- a/conf/docker/init.sh +++ /dev/null @@ -1,4 +0,0 @@ -/usr/sbin/php-fpm7 -/usr/sbin/nginx -echo "KMS-Server initialization completed." -/usr/bin/vlmcsd -De diff --git a/conf/nginx/docker.conf b/conf/nginx/docker.conf deleted file mode 100644 index 0c0b71b..0000000 --- a/conf/nginx/docker.conf +++ /dev/null @@ -1,33 +0,0 @@ -server { - listen 80; - listen [::]:80; - server_name kms.343.re; # 改为自己的域名 - location / { - if ($http_user_agent !~* (curl|wget)) { - return 301 https://$server_name$request_uri; - } - proxy_set_header Host $http_host; - proxy_pass http://127.0.0.1:1689; - } -} - -server { - listen 443 ssl http2; - listen [::]:443 ssl http2; - server_name kms.343.re; # 改为自己的域名 - ssl_certificate /etc/ssl/certs/343.re/fullchain.pem; # 改为自己的证书 - ssl_certificate_key /etc/ssl/certs/343.re/privkey.pem; - - gzip on; - gzip_buffers 32 4K; - gzip_comp_level 6; - gzip_min_length 100; - gzip_types application/javascript text/css text/xml; - gzip_disable "MSIE [1-6]\."; - gzip_vary on; - - location / { - proxy_set_header Host $http_host; - proxy_pass http://127.0.0.1:1689; - } -} diff --git a/conf/nginx/kms.conf b/conf/nginx/kms.conf deleted file mode 100644 index 70f0243..0000000 --- a/conf/nginx/kms.conf +++ /dev/null @@ -1,51 +0,0 @@ -server { - listen 80; - listen [::]:80; - server_name kms.343.re; # 改为自己的域名 - location / { - if ($http_user_agent !~* (curl|wget)) { - return 301 https://$server_name$request_uri; - } - proxy_set_header Host $http_host; - proxy_pass http://127.0.0.1:1689; - } -} - -server { - listen 443 ssl http2; - listen [::]:443 ssl http2; - server_name kms.343.re; # 改为自己的域名 - ssl_certificate /etc/ssl/certs/343.re/fullchain.pem; # 改为自己的证书 - ssl_certificate_key /etc/ssl/certs/343.re/privkey.pem; - - gzip on; - gzip_buffers 32 4K; - gzip_comp_level 6; - gzip_min_length 100; - gzip_types application/javascript text/css text/xml; - gzip_disable "MSIE [1-6]\."; - gzip_vary on; - - location / { - proxy_set_header Host $http_host; - proxy_pass http://127.0.0.1:1689; - } -} - -server { - listen 1689; - root /var/www/kms-server; - - location / { - set $query_param $query_string; - if ($http_user_agent ~* (curl|wget)) { - set $query_param $query_param&cli=true; - } - include fastcgi_params; - fastcgi_pass 127.0.0.1:9000; - fastcgi_param QUERY_STRING $query_param; - fastcgi_param SCRIPT_FILENAME /var/www/kms-server/backend/route.php; - } - - location /assets {} -} diff --git a/conf/vlmcsd.service b/conf/vlmcsd.service deleted file mode 100644 index 5bd98e9..0000000 --- a/conf/vlmcsd.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=KMS Server By vlmcsd -After=network.target - -[Service] -Type=forking -PIDFile=/var/run/vlmcsd.pid -ExecStart=/usr/bin/vlmcsd -p /var/run/vlmcsd.pid -ExecStop=/bin/kill -HUP $MAINPID -PrivateTmp=true - -[Install] -WantedBy=multi-user.target diff --git a/main.php b/main.php index c68b0bd..6c96fbe 100644 --- a/main.php +++ b/main.php @@ -24,9 +24,9 @@ $vlmcsd = array( 'pidFile' => '/run/vlmcsd.pid', ); +logging::info('Loading kms-server (' . $version . ')'); declare(ticks = 1); pcntl_signal(SIGCHLD, 'subExit'); // receive SIGCHLD signal -logging::info('Loading kms-server (' . $version . ')'); new Process($nginx['command']); logging::info('Start nginx server...OK'); diff --git a/conf/docker/kms.conf b/nginx/kms.conf similarity index 76% rename from conf/docker/kms.conf rename to nginx/kms.conf index f2d5f3c..3604bdc 100644 --- a/conf/docker/kms.conf +++ b/nginx/kms.conf @@ -1,6 +1,6 @@ server { listen 1689; - root /var/www/kms-server; + root /kms-server; location / { set $query_param $query_string; @@ -10,7 +10,7 @@ server { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param QUERY_STRING $query_param; - fastcgi_param SCRIPT_FILENAME /var/www/kms-server/backend/route.php; + fastcgi_param SCRIPT_FILENAME /kms-server/src/Route.php; } location /assets {} diff --git a/conf/docker/nginx.conf b/nginx/nginx.conf similarity index 100% rename from conf/docker/nginx.conf rename to nginx/nginx.conf diff --git a/src/Route.php b/src/Route.php new file mode 100644 index 0000000..6274f97 --- /dev/null +++ b/src/Route.php @@ -0,0 +1,3 @@ +