nginx 反向代理微信服务器问题 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
testVmap
V2EX    问与答

nginx 反向代理微信服务器问题

  •  
  •   testVmap 2018-10-19 18:02:58 +08:00 4728 次点击
    这是一个创建于 2625 天前的主题,其中的信息可能已经有所发展或是发生改变。

    需求: 内网服务器 B 需要访问微信服务器,所以做反向代理

    环境配置: 服务器 A 能访问外网 172.16.0.7 服务器 B 不能访问外网

    修改服务器 B 的 hosts 文件,域名指向服务器 A 172.16.0.7 mp.weixin.qq.com

    服务器 A 的 nginx 配置

    server { listen 80; server_name mp.weixin.qq.com; location / { index index.html; proxy_pass https://mp.weixin.qq.com; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_set_header X-Forwarded-proto https; } } server { listen 443; server_name mp.weixin.qq.com; #charset koi8-r; ssl on; ssl_certificate /usr/local/nginx/conf/bundle.crt; ssl_certificate_key /usr/local/nginx/conf/b.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:-LOW:!aNULL:!eNULL; ssl_prefer_server_ciphers on; #access_log logs/host.access.log main; location / { index index.html; proxy_pass https://mp.weixin.qq.com; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_set_header X-Forwarded-proto https; } } 

    结果: 在服务器 B 访问

    http 访问正常

    #curl http://mp.weixin.qq.com/cgi-bin/component {"errmsg":"System Error!!!"} 

    https 访问失败

    #curl https://mp.weixin.qq.com/cgi-bin/component curl: (51) Unable to communicate securely with peer: requested domain name does not match the server's certificate. 

    问题:nginx 改如何配置能够转发 https 的请求

    5 条回复    2018-10-22 23:24:30 +08:00
    whatever93
        1
    whatever93  
       2018-10-19 19:58:10 +08:00 via Android
    证书没过 转不了吧...除非你有公钥私钥
    gftfl
        2
    gftfl  
       2018-10-19 21:59:36 +08:00
    记得 php 在 curl 里是需要 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);跳过证书检查的。
    lihuimail
        3
    lihuimail  
       2018-10-19 22:32:55 +08:00 via Android
    nginx 不能是 http 80 必须是 https
    Dragonish3600
        4
    Dragonish3600  
       2018-10-19 22:45:03 +08:00 via iPhone
    你这样是不行的,你需要用自己一个域名,然后加证书,然后把请求转发到微信域名。类似于中间人的设置才行,不然你证书验证就过不了
    testVmap
        5
    testVmap  
    OP
       2018-10-22 23:24:30 +08:00
    location ^~ /mp/
    {
    #proxy_cache api_cach;
    proxy_set_header Host mp.weixin.qq.com;
    rewrite /mp/(.+)$ /$1 break;
    proxy_pass https://mp.weixin.qq.com;
    }

    最后改成了根据请求路径转发
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2535 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 26ms UTC 15:04 PVG 23:04 LAX 07:04 JFK 10:04
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86