Curl error : No route to host Curl error : No route to host curl curl

Curl error : No route to host


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.


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.


After searching for about a whole day I found that the problem was in the iptables rules.In my case the solution was to restore the iptables rules as follows:

  1. create a file containing the following text:

    *filter

    :INPUT ACCEPT [10128:1310789]

    :FORWARD ACCEPT [0:0]

    :OUTPUT ACCEPT [9631:1361545]

    COMMIT*

  2. run the command: sudo iptables-restore < /path/to/your/previously/created/file

This will hopefully fix your problem if it is an iptables issue.