1

I've been using a fanless ubuntu server for a couple of months and been transferred my Laravel API Passport to different servers like Ubuntu and for development Windows.

The current version of my api is working fine on these servers. Not until when I transferred the laravel project to my AWS Amazon server and getting the error like this

{
"message": "cURL error 6: Could not resolve host: api-a.mydomain.comoauth (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)",
"exception": "GuzzleHttp\\Exception\\ConnectException",
"file": "/var/www/html/api_tk_a/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php",
"line": 185,
"trace": [
{
   ....some line of multiple errors
}
]

}

I tried to add some line of code to my etc/hosts file

like this

52.***.***.205 api-a.mydomain.com 52.***.***.205 api-b.mydomain.com

or

127.0.0.1 api-a.mydomain.com 127.0.0.1 api-b.mydomain.com

tried also my inet addr:171.*.**.** to put on my hosts file still getting the same error

I have 2 different api that's why there's a and b

But nothing of these works.

Can anyone point out the reason why I'm getting this error.

Some thread says this has nothing to do with the Guzzle but clearly states to the IP and DNS. But I can't find a good way to figure this out.

UPDATE

My .env file has something like this

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:1AEVUl5JHMzLkhxU7MDlDHtfZ6KB9UybjzUxLaYp9vg=
APP_DEBUG=true
APP_URL=http://localhost

I tried to put the APP_URL as https://api-a.mydomain.com still not working..

API CODE This code is working fine

$http = new Client;
        $response = $http->post(url('oauth/token'), [
            'form_params' => [
            'grant_type' => 'password',
            'client_id' => '2',
            'client_secret' => '8mEsN0RZkljKZlbiJFfnNKahcbcOVkoQVG7C2Xwl',
            'username' => $user->email,
            'password' => $request->password,
            'scope' => '',
            ],
        ]);

This is my routes/api.php

use Illuminate\Http\Request;
Route::post('/login','Auth\Api\AuthController@login');

EC2 Ping

enter image description here

King RG
  • 478
  • 1
  • 12
  • 27
  • domains api-a.mydomain.com and api-b.mydomain.com are point to your EC2? – Trung Aug 13 '19 at 02:31
  • ec2-user@52.***.***.205, yes. Hmm is there any connection with my `ec2` and my error? – King RG Aug 13 '19 at 02:40
  • can you check inbound rules for EC2? Because to access from outside to EC2 we must be defined inbound rules for EC2. – Trung Aug 13 '19 at 02:45
  • How can I check my `inbound rules for EC2` ? – King RG Aug 13 '19 at 02:46
  • Go to list Instances, and select to your instances. After that show info of Descriptions panel (like as http://prntscr.com/orvz8o) – Trung Aug 13 '19 at 02:49
  • You can try to add All traffic to your EC2 by: Type is All Traffic, Protocal is All, Port Rage is All, Source is 0.0.0.0/0. – Trung Aug 13 '19 at 02:52
  • Me and my colleague trying to follow your instruction what's next sir? – King RG Aug 13 '19 at 03:14
  • done with adding all traffic to my EC2 but still getting the same error and tried to restart my httpd using this command `sudo service httpd restart` – King RG Aug 13 '19 at 03:16
  • Have you tried to ping to your domain? and what is result? can you try replace your domain by Public IP of EC2 instance. – Trung Aug 13 '19 at 03:42
  • I tried to enter my public ip of ec2 to browser and the login interface of laravel `/public/index.php` shows but when I tried to send a request from postman to api guzzle cURL still showing – King RG Aug 13 '19 at 03:46
  • Can you show your code of api function? – Trung Aug 13 '19 at 04:02
  • Sorry late reply had my lunch, I updated my post when codes is included – King RG Aug 13 '19 at 04:57
  • Does the subnet have access to the internet via an Internet Gateway or a Nat Gateway? Check the security groups and network access control lists as well. – strongjz Aug 13 '19 at 08:08
  • In the error message, this looks like a string concat issue. "api-a.mydomain.comoauth" – strongjz Aug 13 '19 at 08:09
  • I didn't change anything on my backend. Maybe this is on the godaddy or aws server. I will try to check on it – King RG Aug 13 '19 at 08:15
  • what would be the reason why `oauth` is with `.com` ? – King RG Aug 13 '19 at 08:28

2 Answers2

0

For ping to work in EC2 instance, you have to open ICMP port in Security Group for your IP. Also for curl, verify have you opened port 8080/80 for your instance.

0

I found a solution:

I used $http->post('https://api-a.mydomain.com' . '/oauth/token', [

Laravel passport trying to get oauth/token. Guzzle keeps hanging, also on other Guzzle calls

King RG
  • 478
  • 1
  • 12
  • 27