Curl error : No route to host

Mihkel Allorg picture Mihkel Allorg · Jul 26, 2016 · Viewed 28.1k times · Source

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.

Answer

Lpgfmk picture Lpgfmk · Aug 17, 2016

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.