问下laravel的https请求如何通过服务器转发?

情况是这样的,我有个项目是在内网里面的,就是不能上微信外网的。
然后对方想要用微信授权登录,这就需要服务器要访问到
api.weixin.qq.com/cgi-bin/token https 的
然后对方就给了一个对外的服务器,这个服务器是能上外网的,内网服务器将请求 api.weixin.qq.com/cgi-bin/token https 的 转到外部服务器,然后让外部服务器去请求,然后把数据给到内网的。
我在外网服务器上安装了一个 nginx,问下这是后 nginx 需要怎么配置转发 https 格式的连接?

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 9

Nginx 配置

server {
    listen                           PORT;
    server_name                      localhost;
    resolver                         114.114.114.114;
    proxy_connect;
    proxy_connect_allow              443 80;
    proxy_connect_read_timeout       10s;
    proxy_coneect_send_timeout       10s;
    proxy_connect_connect_timeout    10s;
    location / {
        proxy_pass $scheme://$http_host$request_uri;
    }
}

直接使用 withOption 方法设置 Proxy

use Illuminate\Support\Facades\Http;

Http::withOptions(['proxy' => 'http[s]://NGINX_IP:PORT'])->get('EXTERNAL_URL');

使用宏

use Illuminate\Support\Facades\Http;

Http::macro('withProxy', function () {
    return Http::withOptions([
        'proxy' => 'http[s]://NGINX_IP:PORT'
    ]);
});

/**
 * @var \Illuminate\Http\Client\Response $response
 */
$response = Http::withProxy()->get('EXTERNAL_URL');
1年前 评论
donggan (楼主) 1年前
GeorgeKing (作者) 1年前
donggan (楼主) 1年前
donggan (楼主) 1年前
donggan (楼主) 1年前
GeorgeKing (作者) 1年前
donggan (楼主) 1年前

直接 nginx 反向代理就行了吧,: 内网服务器通过 ip 访问外网服务器的站点,外网服务器站点返向到微信 api

使用时就是把微信的域名 api.weixin.qq.com 部分换成 http:// 外网 ip: 端口

1年前 评论