From aa999f3b1400a20e091dc0563ba8b6d9058ec97d Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 26 Apr 2021 20:32:47 +0800 Subject: [PATCH] refactor: docker config --- Dockerfile | 17 ++++++----------- README.md | 4 ++-- conf/docker/init.sh | 6 +++--- conf/nginx/docker.conf | 20 ++++++++++---------- conf/nginx/ip.conf | 18 +++++++++--------- 5 files changed, 30 insertions(+), 35 deletions(-) diff --git a/Dockerfile b/Dockerfile index c757ee4..bbfc55e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,8 @@ -FROM debian -COPY . /root +FROM alpine +COPY . /var/www/echoIP ADD ./conf/docker/init.sh / -RUN mkdir -p /var/www/echoIP \ - && mv /root/* /var/www/echoIP/ \ - && apt update \ - && apt install -y nginx curl \ - && apt install -y php7.3 php7.3-fpm php7.3-sqlite3 \ - && apt install -y nodejs \ - && apt clean \ - && cp /var/www/echoIP/conf/nginx/docker.conf /etc/nginx/conf.d \ - && chmod +x /init.sh +RUN apk --update add --no-cache nginx curl nodejs php7 php7-fpm php7-json php7-iconv php7-sqlite3 php7-openssl && \ + mkdir /run/nginx && touch /run/nginx/nginx.pid && \ + cp /var/www/echoIP/conf/nginx/docker.conf /etc/nginx/conf.d && \ + cp /var/www/echoIP/conf/docker/init.sh / CMD ["sh","init.sh"] diff --git a/README.md b/README.md index fb01bc3..9dcfb61 100644 --- a/README.md +++ b/README.md @@ -217,7 +217,7 @@ shell> docker run -dit --name echoip -p 1601:8080 echoip 进入容器调试 ``` -shell> docker exec -it echoip bash +shell> docker exec -it echoip sh ``` ### 部分接口 @@ -233,7 +233,7 @@ qqwry.dat -> 2021-04-21 ipip.net -> 2019-07-03 shell> curl https://ip.343.re/version --user-agent 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36 Edg/90.0.818.42' -{"echoip":"v1.1","qqwry.dat":"20210421","ipip.net":"20190703"} +{"echoip":"v1.1","qqwry":"20210421","ipip":"20190703"} ``` 3. echoIP后端统一接口为 `/query`,可请求以下参数 diff --git a/conf/docker/init.sh b/conf/docker/init.sh index c13bebf..be68f3c 100644 --- a/conf/docker/init.sh +++ b/conf/docker/init.sh @@ -1,4 +1,4 @@ -service php7.3-fpm start -service nginx start +/usr/sbin/php-fpm7 +/usr/sbin/nginx node /var/www/echoIP/backend/qqwryFormat/server.js -/bin/bash +/bin/sh diff --git a/conf/nginx/docker.conf b/conf/nginx/docker.conf index 7e53dd9..c66e980 100644 --- a/conf/nginx/docker.conf +++ b/conf/nginx/docker.conf @@ -1,12 +1,12 @@ server { listen 8080; - root /var/www/echoIP; - - error_page 403 404 = /error.html; - + set $this 127.0.0.1:8080; set_real_ip_from 0.0.0.0/0; real_ip_header X-Real-IP; + root /var/www/echoIP; + error_page 403 404 = /error.html; + location = /ua { if ($http_user_agent ~* (curl|wget)) { return 200 $http_user_agent\n; @@ -18,7 +18,7 @@ server { location = / { set $query_param ?justip=true&cli=true; if ($http_user_agent ~* (curl|wget)) { - proxy_pass http://127.0.0.1:8080/query$query_param; + proxy_pass http://$this/query$query_param; } index index.html; } @@ -28,7 +28,7 @@ server { if ($http_user_agent ~* (curl|wget)) { set $query_param $query_param&cli=true; } - proxy_pass http://127.0.0.1:8080/query$query_param; + proxy_pass http://$this/query$query_param; } location = /version { @@ -36,13 +36,13 @@ server { if ($http_user_agent ~* (curl|wget)) { set $query_param $query_param&cli=true; } - proxy_pass http://127.0.0.1:8080/query$query_param; + proxy_pass http://$this/query$query_param; } location ~* ^/([^/]+?)$ { set $request_ip $1; if ($http_user_agent ~* (curl|wget)) { - proxy_pass http://127.0.0.1:8080/info/$request_ip; + proxy_pass http://$this/info/$request_ip; } } @@ -62,12 +62,12 @@ server { if ($is_legal = 0) { set $query_param $query_param&error=true; } - proxy_pass http://127.0.0.1:8080/query$query_param; + proxy_pass http://$this/query$query_param; } location = /query { include fastcgi_params; - fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; + fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME /var/www/echoIP/backend/queryInfo.php; } } \ No newline at end of file diff --git a/conf/nginx/ip.conf b/conf/nginx/ip.conf index e36fbb6..00a6c43 100644 --- a/conf/nginx/ip.conf +++ b/conf/nginx/ip.conf @@ -25,13 +25,13 @@ server { server { listen 127.0.0.1:1601; - root /var/www/echoIP; - - error_page 403 404 = /error.html; - + set $this 127.0.0.1:1601; set_real_ip_from 0.0.0.0/0; real_ip_header X-Real-IP; + root /var/www/echoIP; + error_page 403 404 = /error.html; + location = /ua { if ($http_user_agent ~* (curl|wget)) { return 200 $http_user_agent\n; @@ -43,7 +43,7 @@ server { location = / { set $query_param ?justip=true&cli=true; if ($http_user_agent ~* (curl|wget)) { - proxy_pass http://127.0.0.1:1601/query$query_param; + proxy_pass http://$this/query$query_param; } index index.html; } @@ -53,7 +53,7 @@ server { if ($http_user_agent ~* (curl|wget)) { set $query_param $query_param&cli=true; } - proxy_pass http://127.0.0.1:1601/query$query_param; + proxy_pass http://$this/query$query_param; } location = /version { @@ -61,13 +61,13 @@ server { if ($http_user_agent ~* (curl|wget)) { set $query_param $query_param&cli=true; } - proxy_pass http://127.0.0.1:1601/query$query_param; + proxy_pass http://$this/query$query_param; } location ~* ^/([^/]+?)$ { set $request_ip $1; if ($http_user_agent ~* (curl|wget)) { - proxy_pass http://127.0.0.1:1601/info/$request_ip; + proxy_pass http://$this/info/$request_ip; } } @@ -87,7 +87,7 @@ server { if ($is_legal = 0) { set $query_param $query_param&error=true; } - proxy_pass http://127.0.0.1:1601/query$query_param; + proxy_pass http://$this/query$query_param; } location = /query {