告诉 Laravel / Nginx 使用代理

Tell Laravel / Nginx to use proxy

解决了我只需要在代码中声明使用代理,看下面的评论@apokryfos 做对了

您好,我正在使用 Nginx 托管网站,mysql 和 php7.2 网站正在使用 laravel 框架。服务器只能通过代理访问互联网,我已经为所有用户设置了代理配置:

sudo nano /etc/environment

文件如下所示:

administrator@orion:/var/www/truckstock$ sudo nano /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/>
http_proxy=http://10.254.234.70:3128/
https_proxy=https://10.254.234.70:3128/

出于所有目的,例如使用 git 设置服务器,composer...代理非常有用。

当我正在访问网站的用户尝试查询外部 API 时出现问题(我们的网站需要从 Monday.com ) which is api2.monday.com 获取一些数据,但连接不起作用,在我的本地服务器(我的笔记本电脑)一切正常。

我的问题是如何告诉 Nginx 或 Laravel 或 Php(不确定是谁发出此请求)使用 porxy?

提前致谢

编辑 1: 下面是执行 api 查询的代码部分的样子

 $query = 'mutation {
change_column_value (board_id: 570045226, item_id: '.$id.', column_id: "status", value: "{\"index\": 11}") {
id
}
}';
    $headers = ['Content-Type: application/json', 'User-Agent: [MYTEAM] GraphQL Client', 'Authorization: ' . $token];
    $data = @file_get_contents($tempUrl, false, stream_context_create([
        'http' => [
            'method' => 'POST',
            'header' => $headers,
            'content' => json_encode(['query' => $query]),
        ]
    ]));
    $tempContents = json_decode($data, true);

所以我所做的就是更改了这段代码:

 $query = 'mutation {
change_column_value (board_id: 570045226, item_id: '.$id.', column_id: "status", value: "{\"index\": 11}") {
id
}
}';
    $headers = ['Content-Type: application/json', 'User-Agent: [MYTEAM] GraphQL Client', 'Authorization: ' . $token];
    $data = @file_get_contents($tempUrl, false, stream_context_create([
        'http' => [
            'method' => 'POST',
            'header' => $headers,
            'content' => json_encode(['query' => $query]),
        ]
    ]));
    $tempContents = json_decode($data, true);

我添加了代理信息所以它是这样的:

$query = 'mutation {
    change_column_value (board_id: 570045226, item_id: '.$id.', column_id: "status", value: "{\"index\": 11}") {
    id
    }
    }';
        $headers = ['Content-Type: application/json', 'User-Agent: [MYTEAM] GraphQL Client', 'Authorization: ' . $token];
        $data = @file_get_contents($tempUrl, false, stream_context_create([
            'http' => [
                'proxy' => 'my proxy', 
                 'request_fulluri' => true
                'method' => 'POST',
                'header' => $headers,
                'content' => json_encode(['query' => $query]),
            ]
        ]));
        $tempContents = json_decode($data, true);