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

2018-10-19 18:02:58 +08:00
 testVmap

需求: 内网服务器 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 的请求

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

最后改成了根据请求路径转发

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/499238

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX