The scheme of visiting Baidu map on Intranet through nginx agent

The scheme of visiting Baidu map on Intranet through nginx agent

Article directory

Preface

  • If the browser environment can not access the external network, but also to achieve the map function, and the server can access the external network, then you can achieve the internal network environment access Baidu map through the agent.

    It's worth noting that this proxy scheme can't solve all the functions of Baidu map, but it can basically satisfy the basic map functions

  • There are two solutions through proxy implementation: first, Download Baidu js manually and replace the address of its domain name as proxy service, which is the simplest way, but not conducive to later update and maintenance; instead, modify the address of its domain name as proxy service through the third-party filtering module, which avoids the disadvantages of manual modification, but because of the introduction of the third-party module, nginx It needs to be recompiled and its reliability is not guaranteed.

    Look up the relevant data and know that nginx has http ﹣ sub ﹣ module that can modify the content returned by the server, but it can only be modified once, and multiple replacement is not supported. However, there is a third-party module on the Internet, NGX ﹣ http ﹣ substitutions ﹣ filter ﹣ module, which can be modified and replaced many times. Unfortunately, it has not been updated for a long time

  • This paper decided to implement in the first way, and the second way is better in theory, but the implementation is more complicated, so we can try it on our own.

The first method is implemented (3 steps)

Get the domain name in js (1)

  • The domain name obtained from http://api.map.baidu.com/getscript is as follows:

    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 Impassability)
    wuxian.baidu.com(ping Impassability)
    static.tieba.baidu.com
    or.map.bdimg.com
    j.map.baidu.com(ping Impassability)
    
    shangetu0.map.bdimg.com
    shangetu1.map.bdimg.com
    shangetu2.map.bdimg.com
    shangetu3.map.bdimg.com
    shangetu4.map.bdimg.com
    
    online0.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.com
    
    gss0.bdstatic.com
    gsp0.baidu.com
    g0.api.map.baidu.com
    g1.api.map.baidu.com
    g2.api.map.baidu.com
    g3.api.map.baidu.com
    
    pcsv0.map.bdimg.com
    pcsv1.map.bdimg.com
    pcsv2.map.bdimg.com
    api0.map.bdimg.com
    api1.map.bdimg.com
    api2.map.bdimg.com
    
  • If the above ping fails, it cannot be added to the nginx configuration. Otherwise, it is similar to an error:
    nginx: [emerg] host not found in upstream "j.map.bdimg.com" in /etc/nginx/conf.d/nginx-bdmap.conf:36

Replace domain name (2)

  • Replace the domain name obtained in js with the proxy service. For example, here, replace api0.map.bdimg.com with [ip]:[port]/api0.map.bdimg.com, where ip, port are the ip and port of the proxy service nginx, and other domain names.

Configure nginx (3)

  • Add the following agent configuration in nginx.conf of nginx, and reload after modification
    	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/;
    	        }
    	}
  • After the above three steps, baidu map can act as an agent

Other

  • Because NGX ﹣ http ﹣ substitutions ﹣ filter ﹣ module is a third-party module, you need to recompile nginx if you want to use it. We can use the official nginx configuration parameter in dockerhub to make some changes to compile the nginx we need
  • The following configuration parameters are obtained from the official nginx query of dockerhub
    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'
    

Reference resources

Enterprise intranet reverse proxy Baidu map service original cloud + community Tencent cloud
https://cloud.tencent.com/developer/article/1185304

Nginx NGX HTTP sub module use iuwai blog Garden
https://www.cnblogs.com/iuwai/p/4432084.html
Nginx uses replace filter nginx module to realize content replacement - feihongying ~ - blog Park
https://www.cnblogs.com/52fhy/p/7956099.html

Manual compilation and installation of nginx - a song of qiushang - blog Garden
https://www.cnblogs.com/luobiao320/p/7189934.html
nginx acts as Baidu map agent to display Baidu map on the intranet - yezip's blog - CSDN blog
https://blog.csdn.net/yezip/article/details/79785480

132 original articles published, praised 37, visited 170000+
Private letter follow

Tags: Nginx network OpenSSL

Posted on Wed, 12 Feb 2020 03:49:05 -0800 by angel_cowgirl