nginx转发百度地图内网化

实测有效:
1.下载百度地图mapApi.js
http://api.map.baidu.com/getscript?v=1.3&key=&services=&t=20121108061854
2.在线格式化代码
3.放到项目里
4.在mapApi.js需要替换的百度请求

    			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 /maponline0.bdimg.com/ {
    	            proxy_pass http://maponline0.bdimg.com/;
    	        }
    	        location /maponline1.bdimg.com/ {
    	            proxy_pass http://maponline1.bdimg.com/;
    	        }
    	        location /maponline2.bdimg.com/ {
    	            proxy_pass http://maponline2.bdimg.com/;
    	        }
    	        location /maponline3.bdimg.com/ {
    	            proxy_pass http://maponline3.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/;
    	        }
    	}

5.nginx配置文件修改


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}



http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
	
	#多个项目时要适量增加
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
	    server {
        listen       8088;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
        		
            proxy_set_header Host baidu.com;
         		proxy_set_header X-Real-IP $remote_addr;
         		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         		proxy_pass http://baidu.com;
        }
        
        location  /bda {
        		
            proxy_set_header Host api.map.baidu.com;
         		proxy_set_header X-Real-IP $remote_addr;
         		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         		proxy_pass http://api.map.baidu.com;
        }
        

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
		server {
        listen       8091;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location /  {       		
            proxy_set_header Host api.map.baidu.com;
         		proxy_set_header X-Real-IP $remote_addr;
         		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         		proxy_pass http://api.map.baidu.com;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }
server {
        listen       8092;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {       		
            proxy_set_header Host shangetu0.map.bdimg.com;
         		proxy_set_header X-Real-IP $remote_addr;
         		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         		proxy_pass http://shangetu0.map.bdimg.com;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

server {
        listen       8093;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {       		
            proxy_set_header Host shangetu1.map.bdimg.com;
         		proxy_set_header X-Real-IP $remote_addr;
         		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         		proxy_pass http://shangetu1.map.bdimg.com;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

server {
        listen       8094;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {       		
            proxy_set_header Host shangetu2.map.bdimg.com;
         		proxy_set_header X-Real-IP $remote_addr;
         		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         		proxy_pass http://shangetu2.map.bdimg.com;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

server {
        listen       8095;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {       		
            proxy_set_header Host shangetu3.map.bdimg.com;
         		proxy_set_header X-Real-IP $remote_addr;
         		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         		proxy_pass http://shangetu3.map.bdimg.com;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}


server {
        listen       8096;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {       		
            proxy_set_header Host shangetu4.map.bdimg.com;
         		proxy_set_header X-Real-IP $remote_addr;
         		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         		proxy_pass http://shangetu4.map.bdimg.com;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}


server {
        listen       8097;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {       		
            proxy_set_header Host maponline0.bdimg.com;
         		proxy_set_header X-Real-IP $remote_addr;
         		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         		proxy_pass http://maponline0.bdimg.com;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}


server {
        listen       8098;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {       		
            proxy_set_header Host maponline1.bdimg.com;
         		proxy_set_header X-Real-IP $remote_addr;
         		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         		proxy_pass http://maponline1.bdimg.com;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}


server {
        listen       8099;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {       		
            proxy_set_header Host maponline2.bdimg.com;
         		proxy_set_header X-Real-IP $remote_addr;
         		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         		proxy_pass http://maponline2.bdimg.com;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}


server {
        listen       9000;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {       		
            proxy_set_header Host maponline3.bdimg.com;
         		proxy_set_header X-Real-IP $remote_addr;
         		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         		proxy_pass http://maponline3.bdimg.com;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}


server {
        listen       9001;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {       		
            proxy_set_header Host map.baidu.com;
         		proxy_set_header X-Real-IP $remote_addr;
         		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         		proxy_pass http://map.baidu.com;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

server {
        listen       9002;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {       		
            proxy_set_header Host loc.map.baidu.com;
         		proxy_set_header X-Real-IP $remote_addr;
         		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         		proxy_pass http://loc.map.baidu.com;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
} 

server {
        listen       9003;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {       		
            proxy_set_header Host api0.map.bdimg.com;
         		proxy_set_header X-Real-IP $remote_addr;
         		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         		proxy_pass http://api0.map.bdimg.com;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}
	
    	server {
    			listen 8065;
    			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 /maponline0.bdimg.com/ {
    	            proxy_pass http://maponline0.bdimg.com/;
    	        }
    	        location /maponline1.bdimg.com/ {
    	            proxy_pass http://maponline1.bdimg.com/;
    	        }
    	        location /maponline2.bdimg.com/ {
    	            proxy_pass http://maponline2.bdimg.com/;
    	        }
    	        location /maponline3.bdimg.com/ {
    	            proxy_pass http://maponline3.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/;
    	        }
    	}
	
	server {
        listen       8066;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location /  {       		
            proxy_set_header Host api.map.baidu.com;
         		proxy_set_header X-Real-IP $remote_addr;
         		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         		proxy_pass http://api.map.baidu.com;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }
	
	server {
        listen       8067;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location /  {       		
            proxy_set_header Host mapv.baidu.com;
         		proxy_set_header X-Real-IP $remote_addr;
         		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         		proxy_pass http://mapv.baidu.com;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }
}

stream{
    server {
        listen       8065;
        proxy_pass smtp.163.com:465;
       }
}

7.在mapApi.js中一个一个替换

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值