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

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

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 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');
2个月前 评论
donggan (楼主) 2个月前
GeorgeKing (作者) 2个月前
donggan (楼主) 2个月前
donggan (楼主) 2个月前
donggan (楼主) 2个月前
GeorgeKing (作者) 2个月前
donggan (楼主) 2个月前

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

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

2个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!