通过nginx代理实现内网访问百度地图方案

文章目录

  • 通过nginx代理实现内网访问百度地图方案
    • 前言
    • 第一种方式实现(3步)
      • 获取js中的域名(1)
      • 替换域名(2)
      • 配置nginx(3)
    • 其他
    • 参考

前言

  • 如果浏览器所在环境不能访问外网,又要实现地图功能,而且服务器能上外网的话,那么就可以通过代理实现内网环境访问百度地图。

    值得注意的是此种代理方案并不能解决所有的百度地图的功能,但对于基本的地图功能还是基本能满足的

  • 通过代理实现有两种方案:一是手动下载百度js,并替换里面的域名为代理服务的地址,此种方式最简单,但不利于后期更新维护;二是通过nginx的过滤模块来修改js里面的域名为代理服务的地址,此种方式虽然省去了手动修改的弊病,但由于引入第三方模块,nginx需要重新编译,可靠性也得不到保障。

    查找相关资料知道nginx有http_sub_module模块可以修改服务器返回的内容,但只能修改一次, 不支持多次替换,而网上有第三方模块ngx_http_substitutions_filter_module则可以多次修改替换,遗憾的是ngx_http_substitutions_filter_module已经很久没更新了

  • 本文决定以第一种方式进行实现,第二种方式理论上更好,但实现较麻烦复杂,可以自行尝试。

第一种方式实现(3步)

获取js中的域名(1)

  • http://api.map.baidu.com/getscript 获得的域名如下:

    map.baidu.com
    sapi.map.baidu.com
    api.map.baidu.com
    its.map.baidu.com
    lbsyun.baidu.com
    loc.map.baidu.com
    webmap0.map.bdimg.com
    mapclick.map.baidu.com(ping不通)
    wuxian.baidu.com(ping不通)
    static.tieba.baidu.com
    or.map.bdimg.com
    j.map.baidu.com(ping不通)shangetu0.map.bdimg.com
    shangetu1.map.bdimg.com
    shangetu2.map.bdimg.com
    shangetu3.map.bdimg.com
    shangetu4.map.bdimg.comonline0.map.bdimg.com
    online1.map.bdimg.com
    online2.map.bdimg.com
    online3.map.bdimg.com
    online4.map.bdimg.com
    ss0.baidu.com
    ss0.bdstatic.com
    d0.map.baidu.com
    d1.map.baidu.com
    d2.map.baidu.com
    d3.map.baidu.comgss0.bdstatic.com
    gsp0.baidu.com
    g0.api.map.baidu.com
    g1.api.map.baidu.com
    g2.api.map.baidu.com
    g3.api.map.baidu.compcsv0.map.bdimg.com
    pcsv1.map.bdimg.com
    pcsv2.map.bdimg.com
    api0.map.bdimg.com
    api1.map.bdimg.com
    api2.map.bdimg.com
    
  • 以上ping不通的不能加到nginx配置里,否则类似错误:
    nginx: [emerg] host not found in upstream “j.map.bdimg.com” in /etc/nginx/conf.d/nginx-bdmap.conf:36

替换域名(2)

  • 将js中获取到的域名替换为代理服务,如在此处将api0.map.bdimg.com替换为[ip]:[port]/api0.map.bdimg.com,其中ip,port则为代理服务nginx的ip和端口,其他域名类推。

配置nginx(3)

  • 在nginx的nginx.conf中增加如下代理配置,修改后重新reload一下
     server {listen 8480;server_name localhost;location /api.map.baidu.com/ {proxy_pass http://api.map.baidu.com/;}      location /sapi.map.baidu.com/ {proxy_pass http://sapi.map.baidu.com/;}location /map.baidu.com/ {proxy_pass http://map.baidu.com/;}location /its.map.baidu.com/ {proxy_pass http://its.map.baidu.com/;}location /lbsyun.baidu.com/ {proxy_pass http://lbsyun.baidu.com/;}location /loc.map.baidu.com/ {proxy_pass http://loc.map.baidu.com/;}location /webmap0.map.bdimg.com/ {proxy_pass http://webmap0.map.bdimg.com/;}location /static.tieba.baidu.com/ {proxy_pass http://static.tieba.baidu.com/;}location /or.map.bdimg.com/ {proxy_pass http://or.map.bdimg.com/;}location /ss0.bdstatic.com/ {proxy_pass http://ss0.bdstatic.com/;}location /ss0.baidu.com/ {proxy_pass http://ss0.baidu.com/;}location /d0.map.baidu.com/ {proxy_pass http://d0.map.baidu.com/;       }location /d1.map.baidu.com/ {proxy_pass http://d1.map.baidu.com/;         }     location /d2.map.baidu.com/ {proxy_pass http://d2.map.baidu.com/; }location /d3.map.baidu.com/ {proxy_pass http://d3.map.baidu.com/;        }location /online0.map.bdimg.com/ {proxy_pass http://online0.map.bdimg.com/;}location /online1.map.bdimg.com/ {proxy_pass http://online1.map.bdimg.com/;}location /online2.map.bdimg.com/ {proxy_pass http://online2.map.bdimg.com/;}location /online3.map.bdimg.com/ {proxy_pass http://online3.map.bdimg.com/;}location /online4.map.bdimg.com/ {proxy_pass http://online4.map.bdimg.com/;}location /shangetu0.map.bdimg.com/ {proxy_pass http://shangetu0.map.bdimg.com/;}location /shangetu1.map.bdimg.com/ {proxy_pass http://shangetu1.map.bdimg.com/;}location /shangetu2.map.bdimg.com/ {proxy_pass http://shangetu2.map.bdimg.com/;}location /shangetu3.map.bdimg.com/ {proxy_pass http://shangetu3.map.bdimg.com/;}location /shangetu4.map.bdimg.com/ {proxy_pass http://shangetu4.map.bdimg.com/;}location /gss0.bdstatic.com/ {proxy_pass http://gss0.bdstatic.com/;}location /gsp0.baidu.com/ {proxy_pass http://gsp0.baidu.com/;}location /g0.api.map.baidu.com/ {proxy_pass http://g0.api.map.baidu.com/;}location /g1.api.map.baidu.com/ {proxy_pass http://g1.api.map.baidu.com/;}location /g2.api.map.baidu.com/ {proxy_pass http://g2.api.map.baidu.com/;}location /g3.api.map.baidu.com/ {proxy_pass http://g3.api.map.baidu.com/;}location /pcsv0.map.bdimg.com/ {proxy_pass http://pcsv0.map.bdimg.com/;}location /pcsv1.map.bdimg.com/ {proxy_pass http://pcsv1.map.bdimg.com/;}location /pcsv2.map.bdimg.com/ {proxy_pass http://pcsv2.map.bdimg.com/;}location /api0.map.bdimg.com/ {proxy_pass http://api0.map.bdimg.com/;}location /api1.map.bdimg.com/ {proxy_pass http://api1.map.bdimg.com/;}location /api2.map.bdimg.com/ {proxy_pass http://api2.map.bdimg.com/;}}
  • 经过以上三步后即可百度地图的代理

其他

  • 由于ngx_http_substitutions_filter_module是第三方模块,因此要使用的话得重新编译nginx,我们可以利用dockerhub里的官方nginx的configure参数来做一些修改即可编译出我们需要的nginx
  • 以下配置参数是从dockerhub 官方nginx查询获得的
    root@034b8504e2f7:/# nginx -V
    nginx version: nginx/1.15.8
    built by gcc 6.3.0 20170516 (Debian 6.3.0-18+deb9u1)
    built with OpenSSL 1.1.0j  20 Nov 2018
    TLS SNI support enabled
    configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-1.15.8/debian/debuild-base/nginx-1.15.8=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'
    

参考

企业内网反向代理百度地图服务 原 - 云+社区 - 腾讯云
https://cloud.tencent.com/developer/article/1185304

nginx ngx_http_sub_module使用 - iuwai - 博客园
https://www.cnblogs.com/iuwai/p/4432084.html
nginx使用replace-filter-nginx-module实现内容替换 - 飞鸿影~ - 博客园
https://www.cnblogs.com/52fhy/p/7956099.html

手动编译安装nginx - 一曲秋殇 - 博客园
https://www.cnblogs.com/luobiao320/p/7189934.html
nginx代理百度地图,实现内网展示百度地图 - yezip的博客 - CSDN博客
https://blog.csdn.net/yezip/article/details/79785480

通过nginx代理实现内网访问百度地图方案相关推荐

  1. 通过nginx代理进行内网mysql的访问

    公网只暴露了一个默认端口,只好想办法访问数据库 选用nginx进行转发.配置如下: stream {upstream cloudsocket {hash $remote_addr consistent ...

  2. Proxifier Socks5 代理(内网访问、远程办公)

    适用场景 远程(在家)办公,访问公司内网 资源下载 代理工具 Proxifier: https://pan.baidu.com/s/13NoMcp1F03GXWt90PzsgPA 提取码: 8d3d ...

  3. Linux:Nginx 正向代理实现内网访问互联网

    前言: 因为公司的某些系统需要访问互联网上的某些功能,每个系统的服务器都开通访问互联网的能力太麻烦并且不方便管理,所以打算只对一台服务器开通访问互联网的能力,并在此服务器基础上搭建 nginx 正向代 ...

  4. Nginx 配置内网访问树莓派4 ASP.NET Core 3.0 网站

    喜迎国庆 点击上方蓝字关注"汪宇杰博客" 导语 前几天发了两篇< 能跑就行:Kestrel Hosting 如果你的要求只是临时内网访问,可以只用 Kestrel 来承载 W ...

  5. Nginx实现 内网访问外网https页面资源的解决方案

    项目场景: 在开发过程中,有遇到在内网环境下 需要访问外网 https页面.遇到这个需求也是比较不好做.经过查询资料和调试最终完成功能. 问题描述 解决思路 : 通过 nginx 反向代理来实现 原因 ...

  6. 使用NGINX代理通过外网连接内网服务器的mysql和redis等

    使用NGINX代理通过外网连接内网服务器的mysql和redis等 前言 使用工具 安装OpenResty 前言 服务器A.B,现在A和B互通,外网可以访问A,但是访问不到B,数据库等中间件安装在B服 ...

  7. 信创环境下Nginx正向代理实现内网发送邮件

    背景 标题党了,其实不管是不是在信创环境,只要存在网络分区/隔离,我们都可能面临发送邮件的问题: 业务服务要发送邮件但是部署在无法连接互联网的环境A中: Nginx一方面作为静态资源服务,另一方面作为 ...

  8. 阿里云oss 使用, 基于Nginx 配置云服务器+oss的内网访问 , 及使用Java SDK 完成上传,下载,删除,查询文件列表操作

    一.同阿里产品,云服务器和存储对象oss-配置内网访问 阿里存储对象oss 地址: https://oss.console.aliyun.com/overview 配置须知 通过Nginx 进行网络转 ...

  9. Java实现Http代理服务器通过http代理进行内网安装yum软件

    Java实现Http代理服务器&通过http代理进行内网安装yum软件 1.Http代理服务器简介 2.Http代理服务器Java实现 2.1 Java源码 2.2 代码分析说明 3.通过ht ...

  10. 端口转发与代理工具 内网代理 内网反弹代理

    目录 一.LCX 二.nc 反弹 三.socks代理工具 四.frp 内网穿透利器 五.ngrok 内网穿透 理论上,任何接入互联网的计算机都是可访问的,但是如果目标主机处于内网,而我们又想和该目标主 ...

最新文章

  1. [云炬python3玩转机器学习笔记] 3-6Numpy数组和矩阵的合并和分割
  2. DeprecationWarning: the md5 module is deprecated; use hashlib instead import md5的解决办法
  3. gVIM+ctags+Taglist+winmanager搭建IDE
  4. Java Web开发与实战_Java Web开发技术与实战项目
  5. python调用ctypes中windll中的方法超时处理_python中使用ctypes调用MinGW生成的动态链接库(dll)...
  6. java getrequest_Java Target.getRequest方法代码示例
  7. 怎么输入license_误执行了 rm fr /* 之后,除了跑路还能怎么办?!
  8. Revit Family API 添加几何实体
  9. 转基因粮食的毒性,首先是因为农药
  10. Objective-C写出Json文件(可作配置文件)
  11. 【AMAD】django-compressor -- 将JS和CSS文件压缩为一个缓存文件
  12. 拼多多笔试_探险家冒险和大数问题
  13. P1137【旅行计划】
  14. 出席华盛顿大学以人为本用户体验设计领导力活动 探讨区块链的用户体验 | ArcBlock 活动...
  15. 编辑为什么建议转投_为何投文章总被拒?听听期刊编辑的干货建议
  16. CDN-内容推送网络
  17. K_A19_002 基于STM32等单片机采集水位检测传感数据 串口与OLED0.96双显示
  18. 怎么实现使用手机号、邮箱、用户名登录
  19. Dell E7440加装硬盘
  20. 四周无人机的姿态解算(2)

热门文章

  1. 和你走在南京种满梧桐的大街小巷
  2. 百度地图API获取公交路线及站点数据
  3. 华为设备配置SEP多环
  4. 费马大定理四分之一解决
  5. 根目录在哪里 根目录下的目录有什么作用
  6. python fun函数输入某年某月_Python编程实现输入某年某月某日计算出这一天是该年第几天的方法...
  7. 博纳影业明日上市:于冬陷入与江疏影绯闻 被曝斥资千万买珠宝
  8. 【产品经理】产品经理进阶之路-大纲
  9. 关于outlook不能发送126邮件的问题
  10. pat basic 1096 大美数