Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curl error : No route to host

So we're building a web application in PHP and we're trying to make requests to an external API. Problem is that we're getting a curl error:

cURL error 7: Failed to connect to external.api.com port 443: No route to host

A little bit of background now.

  • We're making requests using Guzzle.
  • We're hosting on Apache, which is running on a Linux machine and we're also using SSL.
  • The API is also using SSL, therefore the port 443 in error message.
  • The HTTP requests include a certificate for authentication.

I've managed to get it running on two different development environments but not on the production one. I suspect the problem is in the configuration of Apache, as if we haven't made it available to make requests to certain IP or port. I have no idea how to check it. I've read that I might have to change the file /etc/network/interface yet I haven't found any info on what to write there.

I've also read I have to run $ netstat -rn for answers yet I'm not sure what to look there.

EDIT:

Can't even make a simple get request without any parameters and anything. Yet I can make requests to https://google.com and https://facebook.com. Will write more in a few.

like image 914
Mihkel Allorg Avatar asked Jul 26 '16 12:07

Mihkel Allorg


3 Answers

After a lot of debugging and testing all of my code I contacted the service, whose API I was trying to consume.

They were an European service provider and they had whitelisted European IP's. Our production server was in the USA and after they whitelisted our IP, everything worked.

like image 105
Mihkel Allorg Avatar answered Sep 17 '22 17:09

Mihkel Allorg


It worked for me for apache (httpd)

iptables -I INPUT -p tcp --dport 80 -j ACCEPT
like image 28
prograshid Avatar answered Sep 20 '22 17:09

prograshid


netstat -aln | grep 443 will show if your webserver is listening on that port.

Depending on which webserver you have installed your configuration file, for the site will be at /etc/nginx/sites-available/default, /etc/nginx/sites-available/yourSite, /etc/nginx/nginx.conf or some other similar paths for apache.

Wherever it is located, your configuration file should contain something like the following:

server {
listen 80;
listen 443 ssl;
server_name yourSite.com;
root "/path/to/yourSite";

index index.html index.htm index.php;

charset utf-8;

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt  { access_log off; log_not_found off; }

access_log off;
error_log  /path/to/webserver/youSite.error.log error;

sendfile off;

client_max_body_size 100m;

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    fastcgi_intercept_errors off;
    fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
}

location ~ /\.ht {
    deny all;
}

ssl_certificate     /path/to/yourSite.crt;
ssl_certificate_key /path/to/yourSite.key;
}

After changing this file make sure to sudo service nginx reload or sudo service nginx restart (or the relative apache command).

sudo service nginx configtest or sudo nginx -t will help with debugging the config file.

like image 37
Lpgfmk Avatar answered Sep 20 '22 17:09

Lpgfmk