mirror of https://github.com/dnomd343/echoIP
Dnomd343
4 years ago
5 changed files with 238 additions and 113 deletions
@ -0,0 +1,48 @@ |
|||
## Nginx配置 |
|||
|
|||
### 方式A |
|||
|
|||
需要两个配置文件 `ip.conf` 和 `ip-sub.func` |
|||
|
|||
``` |
|||
# 进入nginx配置目录 |
|||
shell> cd /etc/nginx/conf.d |
|||
|
|||
# 从代码仓库复制配置文件 |
|||
shell> cp /var/www/echoIP/conf/nginx/methodA/ip.conf ./ |
|||
shell> cp /var/www/echoIP/conf/nginx/methodB/ip-sub.func ./ |
|||
|
|||
# 修改配置文件,将ip.343.re改为需要部署的域名 |
|||
shell> vim ip.conf |
|||
··· |
|||
shell> vim ip-sub.func |
|||
··· |
|||
``` |
|||
|
|||
重启Nginx服务 |
|||
|
|||
``` |
|||
shell> nginx -s reload |
|||
``` |
|||
|
|||
### 方式B |
|||
|
|||
需要一个配置文件 `ip.conf` ,但需要额外占用除80与443之外的一个端口,默认为TCP/1601,可按需修改 |
|||
|
|||
``` |
|||
# 进入nginx配置目录 |
|||
shell> cd /etc/nginx/conf.d |
|||
|
|||
# 从代码仓库复制配置文件 |
|||
shell> cp /var/www/echoIP/conf/nginx/methodB/ip.conf ./ |
|||
|
|||
# 修改配置文件,将ip.343.re改为需要部署的域名 |
|||
shell> vim ip.conf |
|||
··· |
|||
``` |
|||
|
|||
重启Nginx服务 |
|||
|
|||
``` |
|||
shell> nginx -s reload |
|||
``` |
@ -0,0 +1,73 @@ |
|||
root /var/www/echoIP; |
|||
resolver 8.8.8.8; |
|||
|
|||
location = / { |
|||
if ($http_user_agent ~* (curl|wget)) { |
|||
return 200 $remote_addr\n; |
|||
} |
|||
if ($scheme = http) { |
|||
return 301 https://$server_name; |
|||
} |
|||
index index.html; |
|||
} |
|||
|
|||
location = /ua { |
|||
if ($http_user_agent ~* (curl|wget)) { |
|||
return 200 $http_user_agent\n; |
|||
} |
|||
default_type application/json; |
|||
return 200 $http_user_agent; |
|||
} |
|||
|
|||
location = /ip { |
|||
if ($http_user_agent ~* (curl|wget)) { |
|||
return 200 $remote_addr\n; |
|||
} |
|||
if ($scheme = http) { |
|||
return 301 https://$server_name/ip; |
|||
} |
|||
return 200 $remote_addr; |
|||
} |
|||
|
|||
location ~* ^/([^/]+?)$ { |
|||
set $request_ip $1; |
|||
if ($http_user_agent ~* (curl|wget)) { |
|||
proxy_pass https://ip.343.re/info/$request_ip; # 改成自己的域名 |
|||
break; |
|||
} |
|||
if ($scheme = http) { |
|||
return 301 https://$server_name$request_uri; |
|||
} |
|||
} |
|||
|
|||
location ^~ /info { |
|||
set $is_cli 0; |
|||
set $is_https 0; |
|||
set $is_legal 0; |
|||
if ($uri ~* ^/info/?$) { |
|||
set $is_legal 1; |
|||
set $query ip=$remote_addr; |
|||
} |
|||
if ($uri ~* ^/info/([^/]+?)$) { |
|||
set $is_legal 1; |
|||
set $query ip=$1; |
|||
} |
|||
if ($is_legal = 0) { |
|||
return 404; |
|||
} |
|||
if ($scheme = https) { |
|||
set $is_https 1; |
|||
} |
|||
if ($http_user_agent ~* (curl|wget)) { |
|||
set $is_cli 1; |
|||
set $query $query&cli=true; |
|||
} |
|||
set $flag_https_cli $is_https$is_cli; |
|||
if ($flag_https_cli = 00) { |
|||
return 301 https://$server_name$request_uri; |
|||
} |
|||
include fastcgi_params; |
|||
fastcgi_pass 127.0.0.1:9000; # php-fpm接口 |
|||
fastcgi_param QUERY_STRING $query; |
|||
fastcgi_param SCRIPT_FILENAME /var/www/echoIP/backend/queryInfo.php; |
|||
} |
@ -0,0 +1,13 @@ |
|||
server { |
|||
listen 80; |
|||
server_name ip.343.re; # 改为自己的域名 |
|||
include conf.d/ip-sub.func; |
|||
} |
|||
|
|||
server { |
|||
listen 443 ssl http2; |
|||
server_name ip.343.re; # 改为自己的域名 |
|||
ssl_certificate /etc/ssl/certs/343.re/fullchain.pem; # 改为自己的证书 |
|||
ssl_certificate_key /etc/ssl/certs/343.re/privkey.pem; |
|||
include conf.d/ip-sub.func; |
|||
} |
@ -0,0 +1,83 @@ |
|||
server { |
|||
listen 80; |
|||
server_name ip.343.re; # 改为自己的域名 |
|||
location / { |
|||
if ($http_user_agent !~* (curl|wget)) { |
|||
return 301 https://$server_name$request_uri; |
|||
} |
|||
proxy_set_header X-Real-IP $remote_addr; |
|||
proxy_pass http://127.0.0.1:1601; # 自定义端口 |
|||
} |
|||
} |
|||
|
|||
server { |
|||
listen 443 ssl http2; |
|||
server_name ip.343.re; # 改为自己的域名 |
|||
ssl_certificate /etc/ssl/certs/343.re/fullchain.pem; # 改为自己的证书 |
|||
ssl_certificate_key /etc/ssl/certs/343.re/privkey.pem; |
|||
location / { |
|||
proxy_set_header X-Real-IP $remote_addr; |
|||
proxy_pass http://127.0.0.1:1601; # 自定义端口 |
|||
} |
|||
} |
|||
|
|||
server { |
|||
listen 1601; # 自定义端口 |
|||
root /var/www/echoIP; |
|||
|
|||
set_real_ip_from 0.0.0.0/0; |
|||
real_ip_header X-Real-IP; |
|||
|
|||
location = / { |
|||
if ($http_user_agent ~* (curl|wget)) { |
|||
return 200 $remote_addr\n; |
|||
} |
|||
index index.html; |
|||
} |
|||
|
|||
location = /ua { |
|||
if ($http_user_agent ~* (curl|wget)) { |
|||
return 200 $http_user_agent\n; |
|||
} |
|||
default_type application/json; |
|||
return 200 $http_user_agent; |
|||
} |
|||
|
|||
location = /ip { |
|||
if ($http_user_agent ~* (curl|wget)) { |
|||
return 200 $remote_addr\n; |
|||
} |
|||
return 200 $remote_addr; |
|||
} |
|||
|
|||
location ~* ^/([^/]+?)$ { |
|||
set $request_ip $1; |
|||
if ($http_user_agent ~* (curl|wget)) { |
|||
proxy_pass http://127.0.0.1:1601/info/$request_ip; # 自定义端口 |
|||
} |
|||
} |
|||
|
|||
location ^~ /info { |
|||
set $is_cli 0; |
|||
set $is_https 0; |
|||
set $is_legal 0; |
|||
if ($uri ~* ^/info/?$) { |
|||
set $is_legal 1; |
|||
set $query ip=$remote_addr; |
|||
} |
|||
if ($uri ~* ^/info/([^/]+?)$) { |
|||
set $is_legal 1; |
|||
set $query ip=$1; |
|||
} |
|||
if ($is_legal = 0) { |
|||
return 404; |
|||
} |
|||
if ($http_user_agent ~* (curl|wget)) { |
|||
set $query $query&cli=true; |
|||
} |
|||
include fastcgi_params; |
|||
fastcgi_pass 127.0.0.1:9000; # php-fpm接口 |
|||
fastcgi_param QUERY_STRING $query; |
|||
fastcgi_param SCRIPT_FILENAME /var/www/echoIP/backend/queryInfo.php; |
|||
} |
|||
} |
Loading…
Reference in new issue