惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recorded Future
Recorded Future
Microsoft Security Blog
Microsoft Security Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
人人都是产品经理
人人都是产品经理
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
有赞技术团队
有赞技术团队
Stack Overflow Blog
Stack Overflow Blog
H
Help Net Security
Apple Machine Learning Research
Apple Machine Learning Research
The Cloudflare Blog
B
Blog RSS Feed
小众软件
小众软件
博客园 - 叶小钗
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 聂微东
博客园_首页
B
Blog
雷峰网
雷峰网
S
SegmentFault 最新的问题
N
Netflix TechBlog - Medium
D
Docker
博客园 - 司徒正美
博客园 - 【当耐特】
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
MongoDB | Blog
MongoDB | Blog
U
Unit 42
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
腾讯CDC
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
Jina AI
Jina AI
WordPress大学
WordPress大学
D
DataBreaches.Net
V
V2EX
V
Visual Studio Blog
Know Your Adversary
Know Your Adversary
P
Privacy & Cybersecurity Law Blog
F
Full Disclosure
G
Google Developers Blog
Engineering at Meta
Engineering at Meta
The Hacker News
The Hacker News
Security Archives - TechRepublic
Security Archives - TechRepublic
IT之家
IT之家
P
Privacy International News Feed

博客园 - 一望无际的南

wps转PDF-解决IPAD中PDF乱码问题 thinkserver TS250 虚拟化主机部署 小微企业的数据备份方案 mac idea 修改git账号 coder,不要做计算机,好吗? mac 同一应用多实例的切换 沙雕的git Plugin 一行命令完成linux对文件的授权 jira 8.x 性能调优 NODEJS npm build 中哪些乱码是什么? DT 还是IT 混乱的docker swarm 版本在运维的重要性 nginx 在linux下端口被禁用问题 bitbucket灾难恢复或者服务迁移指南 2020年服务器迁移 当,规范什么都不是 gradle介绍 Centos7 改名问题
记阿里云SLB后配置Nginx反向代理百度地图API的坑
一望无际的南 · 2018-09-03 · via 博客园 - 一望无际的南

需求

百度的原始请求:
https://api.map.baidu.com/place/v2/suggestion?query=s&region=sc&city_limit=true&output=json&ak=dl0tuE2WhjbHyqKcHevxXRYnLjV53OZm

代理为:

https://api.example.com/proxy/baidu/suggestion?query=s&region=sc&city_limit=true&output=json&ak=dl0tuE2WhjbHyqKcHevxXRYnLjV53OZm

顺序

Client –》 SLB –》 Nginx-Proxy –>baidu.com api   -阿里云环境

Clinet –>Nginx  -> Nginx-Proxy –>baidu.com api  - 测试环境

问题

在自建环境中,没有任何问题,但是发布到阿里云SLB(service load balance)之后,居然百度端会报
参数无效。

我们是采用Bitbucket来管理Nginx-proxy, 由于采用的是Docker执行,整体上倒是很方便,就是相比直接部署来说,每次发布时间要长一些。(由于是全自动化,倒是可以喝个水,溜下单身狗什么的)

image

# in QA, it works well with SLB
    location ^~/proxy/baidu/ {
            #support cross-domain visit for app
           
            add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
            #allow credentials
            add_header Access-Control-Allow-Credentials true;
            #allow-headers
            add_header 'access-control-allow-headers' 'Authentication,Origin,X-Requested-With,Content-Type,Accept,token,appId,unitId';
            
            #alias //;
       #     proxy_set_header X-Real-IP $remote_addr;
        #    proxy_set_header REMOTE-HOST $remote_addr;
         #   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      
            proxy_pass http://api.map.baidu.com/place/v2/;
            #proxy_redirect https://api.map.baidu.com/place/v2// /;
      
            #proxy_pass http://node-http/log/testGet/;
            #proxy_redirect http://node-http/log/testGet// /;
    }

检查过程

由于采用docker部署方式,理论上说都是一样的。唯一可能的是:SLB那边转发做了一定的改动。因此,采用tcpdump来抓包,比较两个环境下的转发请求的不同

其实,我最开始的时候,采用的是Node-http来获得Nginx-Proxy 请求

Client –》 SLB –》 Nginx-Proxy –>baidu.com api   -阿里云环境 改为

Client –》 SLB –》 Nginx-Proxy –>Node Http

通过捕获Http请求,来比较两个环境下请求有哪些不同。其实两种工具都可以: Node Http 或者采用 Tcpdump 来获得请求。

比较结果:
image

发现过程就是用firefox的web Tool不停的编辑header头,做测试了,直到。。。

最终发现是:由于在配置SLB的时候增加了一个header造成的,去掉就可以了。

X-Forwarded-Proto: https\r\n

在此期间分别向阿里云和百度提交了工单,阿里云的工程师回复比较积极,百度就呵呵了。有可能用的百度地图服务是免费的,因此人家呵呵。

后面补充一点

由于在Nginx-Proxy docker中即要启动Nginx,同时,又需要启动tcpdump,因此需要安装了s6-svscan 服务驻守程序。

我简单把dockerfile内容供参考吧

FROM nginx:1.12.1-alpine

RUN apk update 
RUN apk add tcpdump
RUN apk add s6


COPY ./services /etc/s6/services
RUN chmod +x  /etc/s6/services/nginx/run
RUN chmod +x  /etc/s6/services/nginx/finish

RUN chmod +x  /etc/s6/services/tcpdump/run
RUN chmod +x  /etc/s6/services/tcpdump/finish



CMD ["s6-svscan", "/etc/s6/services"]

注意要自己编写 services目录下面的服务启动文件 run和关闭文件finish,具体的大家google一下吧(为什么不百度,因为它呵呵我。)

能够关掉任务很开心

image