Reputation: 91
Solved i just had to declare in the code to use proxy, see comments below @apokryfos got it right
Hi i am hosting the website using Nginx, mysql and php7.2 website is using laravel framework. The server has only access to the internet trough proxy, i have set the proxy config for all users like this in:
sudo nano /etc/environment
And here is how the file looks:
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/
For all the purposes like setting up server using git, composer... proxy works like a charm.
The problem comes up when i user who is visting website tries to query external API ( Our website needs to get some data from Monday.com ) which is api2.monday.com the connection just doesn't work and on my local server ( My Laptop ) everything works fine.
My question is how can i tell Nginx or Laravel or Php ( Not sure who is making this request ) to use porxy?
Thanks in advance
EDIT 1: Here is how the part of the code doing the api query looks
$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);
Upvotes: 1
Views: 322
Reputation: 91
So what i did was i changed this code:
$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);
And i added proxy information so it came like this:
$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);
Upvotes: 1