Skip to content
公告

获取IP地址位置信息的API接口

在开发特定主题的项目时,会遇到IP归属地的问题。为了解决这个问题,我在这里分享了一些免费的IP地址归属地查询API接口,供您参考和使用。这些接口可以帮助您查询指定IP的位置信息,仅供参考。

  1. 百度IP地址归属地查询接口: 请求接口:http://opendata.baidu.com/api.php?apiquery=123.123.123.123&co=&resource_id=6006&oe=utf8 返回结果包括国家、省份、城市等信息。
  2. 太平洋IP地址归属地查询接口: 请求接口:http://whois.pconline.com.cn/ipJson.jsp?ip=123.123.123.123&json=true 返回结果包括国家、省份、城市等信息。此外,如果IP地址为空,接口还可以根据网络定位返回设备位置信息。
  3. www.ip.cn IP地址归属地查询接口: 请求接口:https://www.ip.cn/api/index?ip&type=0 返回结果包括国家、省份、城市等信息。
  4. ip-api.com IP地址归属地查询接口: 请求接口:http://ip-api.com/json/123.123.123.123?lang=zh-CN 返回结果包括国家、省份、城市等信息。此外,接口支持切换显示语言。
  5. 2023.ipchaxun.com IP地址归属地查询接口: 请求接口:https://2023.ipchaxun.com/ 返回结果包括国家、省份、城市等信息。
  6. CSDN IP地址归属地查询接口: 请求接口:https://searchplugin.csdn.net/api/v1/ip/get?ip=123.123.123.123 返回结果包括国家、省份、城市等信息。
  7. www.ipplus360.com IP地址归属地查询接口: 请求接口:https://www.ipplus360.com/getIP 返回结果包括国家、省份、城市等信息。
  8. ip.useragentinfo.com IP地址归属地查询接口: 请求接口:https://ip.useragentinfo.com/json?ip=123.123.123.123 返回结果包括国家、省份、城市等信息。

Docker部署nginx+php环境

旧的方案

docker run --name myphp-fpm -v /root/vitepress/SB:/www -d php:7.4-fpm
docker run --name 01-nginx-SB2 -p 8999:80 -d -v /root/vitepress/SB:/usr/share/nginx/html -v /root/vitepress/SB/default.conf:/etc/nginx/nginx.conf --link myphp-fpm:php nginx:latest

新的方案

bash
# //docker-compose-php-nginx.yaml
echo "version: '3'  
services:  
  nginx:
    image: nginx:latest  
    ports:  
      - "8999:80"  
    volumes:  
      - /root/vitepress/SB:/usr/share/nginx/html  
      - /root/vitepress/SB/default.conf:/etc/nginx/nginx.conf  
    restart: always
    networks:  
      - mynetwork
    container_name: 01-nginx-SB2
  phpfpm:  
    image: php:8.3.6-fpm  
    volumes:  
      - /root/vitepress/SB:/www  
    environment:
      - TZ=Asia/Shanghai 
    restart: always
    networks:  
      - mynetwork  
    container_name: myphp-fpm
networks:  
  mynetwork:" >docker-compose-nastool-php-nginx.yaml

启动

bash
docker-compose -p php-nginx -f docker-compose-nastool-php-nginx.yaml up -d
sh
# //default.conf
user nginx;  # Nginx 服务的运行用户  
worker_processes 1;  # 工作进程数,通常设置为 CPU 核心数  
  
events {    
    worker_connections 1024;  # 单个 worker process 允许的最大连接数  
}    
  
http {    
    include mime.types;  # 包含 MIME 类型定义文件  
    default_type application/octet-stream;  # 默认的 MIME 类型  
  
    sendfile on;  # 开启 sendfile,提高文件传输效率  
    keepalive_timeout 65;  # 长连接超时时间  
  
    server {    
        listen 80;  # 监听 80 端口  
        server_name localhost;  # 服务器名  
  
        # 配置根路径及默认文件  
        location / {    
            root /usr/share/nginx/html;  # 静态文件的根目录  
            index index.html index.htm index.php;  # 默认的索引文件  
            try_files $uri $uri/ /index.php?$query_string;  # 支持 PHP 的前端控制器模式  
        }    
  
        # 配置 404 错误页面  
        error_page 404 /404.html;    
        location = /404.html {    
            root /usr/share/nginx/html;    
            internal;  # 仅允许内部重定向访问  
        }    
  
        # 禁止直接访问隐藏文件  
        location ~ /\. {    
            deny all;  # 拒绝所有请求  
            access_log off;  # 关闭访问日志  
            log_not_found off;  # 关闭“文件未找到”日志  
        }    
  
        # PHP 处理配置  
        location ~ \.php$ {  
            fastcgi_pass   myphp-fpm:9000;  # PHP-FPM 地址及端口  
            fastcgi_index  index.php;  # 默认的 PHP 索引文件  
            # SCRIPT_FILENAME 参数传递给 PHP 处理器,注意这里的路径可能需要根据你的实际环境进行修改  
            fastcgi_param  SCRIPT_FILENAME  /www/$fastcgi_script_name;    
            include        fastcgi_params;  # 包含 PHP 处理器需要的其它参数  
        }  

        location = /123/data.sqlite {  
        deny all;  
        return 404 'Not Found';  
        }
  
        # 其他错误页面配置  
        error_page 500 502 503 504 /50x.html;    
        location = /50x.html {    
            root /usr/share/nginx/html;    
        }    
    }    
}

本博客为分享文档,仅供个人学习参考。