php - 告诉 Laravel / Nginx 使用代理
问题描述
解决了我只需要在代码中声明使用代理,请参阅下面的评论@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获取一些数据)这是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);
推荐阅读
- java - 如何为跳棋同步 AI MinMax 算法?伪代码
- database - FutureBuilder 与 Streambuilder
- mysql - CURRENT_TIMESTAMP 的 SQL 日期时间值不正确.....有时
- react-native - 如何在 render() 方法中调用函数并保持其纯净?
- debian - Debian 无人值守升级不安装软件包
- node.js - 如何获取用户的响应,该响应属于对话框流中的默认回退意图
- angular - 角材料芯片激活芯片ngclass
- typescript - 类型'{商店:MockStoreEnhanced
; }' 不可分配给类型 'IntrinsicAttributes & Pick[...] - firebase - 使用 HUGO 框架在 Github Workflow for Firebase Web App 中需要 CI 和 CD 帮助
- c# - 如何绑定字典
到 Xamarin 表单中的 XAML