内网访问高德地图nginx代理
項目需求:A服務(wù)器在內(nèi)網(wǎng),不能訪問互聯(lián)網(wǎng),B服務(wù)器在外網(wǎng),可以訪問互聯(lián)網(wǎng),客戶端電腦只能訪問A服務(wù)器,客戶端電腦怎么訪問高德地圖?
實現(xiàn)思路:客戶端訪問A服務(wù)器,A再訪問B服務(wù)器,B請求高德地圖api js并返回給A服務(wù)器,A服務(wù)器nginx安裝ngx_http_sub_module模塊,將api js中的所有域名替換成自己的代理地址再返回給客戶端
注意事項:
1、下面配置只實現(xiàn)了基本的地圖功能,如需實現(xiàn)更復雜的功能,還需代理如下地址
http://www.w3.org、https://gaode.com、http://m.amap.com、http://vector.amap.com、http://a.amap.com
2、http://vdata.amap.com/style_icon/icon-normal-small.png?、http://vdata.amap.com/style_icon/icon-biz-small.png 這兩個圖片集是在動態(tài)腳本中訪問的,所以需要將eval(b)和eval(fd)中的腳本替換一下
3、如果客戶端電腦可以直接訪問B服務(wù)器的話,可以將兩個配置文件合并,只在B服務(wù)器安裝一個nginx即可
A服務(wù)器nginx配置:
server {listen 8080;server_name localhost;location /maps {proxy_set_header Accept-Encoding "";proxy_pass http://B服務(wù)器ip:8080/maps;sub_filter_types *;sub_filter_once off;sub_filter 'http://webapi.amap.com' 'http://B服務(wù)器ip:8080/webapi';sub_filter 'http://restapi.amap.com' 'http://B服務(wù)器ip:8080/restapi';sub_filter 'http://vdata.amap.com' 'http://B服務(wù)器ip:8080/vdata';sub_filter '/webapi.amap.com' '/B服務(wù)器ip:8080\/webapi';sub_filter '/restapi.amap.com' '/B服務(wù)器ip:8080\/restapi';sub_filter '/vdata.amap.com' '/B服務(wù)器ip:8080\/vdata';sub_filter 'webapi.amap.com' 'B服務(wù)器ip:8080/webapi';sub_filter 'restapi.amap.com' 'B服務(wù)器ip:8080/restapi';sub_filter 'vdata.amap.com' 'B服務(wù)器ip:8080/vdata';sub_filter 'wprd0{1,2,3,4}.is.autonavi.com' 'B服務(wù)器ip:8080/wprd0{1,2,3,4}';sub_filter 'eval(b)' 'eval(b.replace(/vdata\.amap\.com/g,"B服務(wù)器ip:8080/vdata"))';sub_filter 'eval(fd)' 'eval(fd.replace(/vdata\.amap\.com/g,"B服務(wù)器ip:8080/vdata"))';}location / {proxy_pass http://172.16.10.180:8080;} }B服務(wù)器nginx配置:
server {listen 8080;server_name localhost;location /maps {resolver 8.8.8.8;set $backend "webapi.amap.com";proxy_pass http://$backend;}location ~* ^/webapi(.*) {resolver 8.8.8.8;set $backend "webapi.amap.com";proxy_pass http://$backend$1$is_args$args;}location ~* ^/restapi(.*) {resolver 8.8.8.8;set $backend "restapi.amap.com";proxy_pass http://$backend$1$is_args$args;}location ~* ^/vdata(.*) {resolver 8.8.8.8;set $backend "vdata.amap.com";proxy_pass http://$backend$1$is_args$args;}location ~* ^/wprd0(\d*)/(.*) {resolver 8.8.8.8;set $backend "is.autonavi.com";proxy_pass http://wprd0$1.$backend/$2$is_args$args;} }?
總結(jié)
以上是生活随笔為你收集整理的内网访问高德地图nginx代理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 从零开始写渲染Step1窗口的创建和显示
- 下一篇: 从Alexander Egyed的论文看