nginx 代理的后端为https
-
1、需求:接入层有一个nginx,代理后端所有的服务都走的http,突然有一天接入了一个平台走的https(https://192.168.1.1)也需要通过接入层的nginx进行代理
-
2、配置
########### 测试nginx 代理https start ##########
server {
listen 10080 default_server;
server_name _;
location /aaa {
proxy_pass https://httpbin.org/get; # 代理到目标 HTTPS 服务
proxy_set_header Host $host; # 保留原始请求的 Host 头
proxy_set_header X-Forwarded-Proto $scheme; # 传递原始请求的协议(http/https)
access_log /tmp/baidu_access.log main; # 自定义日志文件
}
}
########### 测试nginx 代理https end ##########
nginx -t
nginx -s reload
- 3、验证
curl http://localhost:10080/aaa
{
"args": {},
"headers": {
"Accept": "*/*",
"Host": "localhost",
"User-Agent": "curl/7.29.0",
"X-Amzn-Trace-Id": "Root=1-6736b041-1d8584a713cbfd1e7089cd7c"
},
"origin": "111.202.167.97",
"url": "https://localhost/get"
}
- 4、上线。把nginx的配置发给同事做线上配置的时候理论只需要替换<proxy_pass https://httpbin.org/get;>就可以了,但实际上到线上以后访问报403
- 排查思路:检查nginx日志
- 解决思路:最小化配置。注释掉 #proxy_set_header Host $host; # 保留原始请求的 Host 头后403的问题解决,应该是https服务对客户端的访问ip有白名单限制(待验证)
location /aaa {
proxy_pass https://httpbin.org/get; # 代理到目标 HTTPS 服务
proxy_set_header Host $host; # 保留原始请求的 Host 头
proxy_set_header X-Forwarded-Proto $scheme; # 传递原始请求的协议(http/https)
access_log /tmp/baidu_access.log main; # 自定义日志文件
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
2018-11-15 MySQL用户授权