Browse Source

refactor: docker config

master
Dnomd343 4 years ago
parent
commit
aa999f3b14
  1. 17
      Dockerfile
  2. 4
      README.md
  3. 6
      conf/docker/init.sh
  4. 20
      conf/nginx/docker.conf
  5. 18
      conf/nginx/ip.conf

17
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"]

4
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`,可请求以下参数

6
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

20
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;
}
}

18
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 {

Loading…
Cancel
Save