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"
}
- 排查思路:检查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;  # 自定义日志文件
    }

posted @   Hello_worlds  阅读(293)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
历史上的今天:
2018-11-15 MySQL用户授权
点击右上角即可分享
微信分享提示