6

This question shows research effort; it is useful and clear

I have checked the cURL not working properly

When I run the command curl -I https://www.example.com/sitemap.xml

curl: (7) Failed to connect

Failed to connect on all port

this error only on one domain, all other domain working fine, curl: (7) Failed to connect to port 80, and 443

Thanks...

8 Answers 8

16

First Check your /etc/hosts file entries, may be the URL which You're requesting, is pointing to your localhost.

If the URL is not listed in your /etc/hosts file, then try to execute following command to understand the flow of Curl Execution for the particular URL:

curl --ipv4 -v "https://example.com/";
9

After many search, I found that Hosts settings not correct

Then I check nano /etc/hosts The Domain point to wrong IP in hosts file

I change the wrong IP and its working Fine

This is new error Related to curl: (7) Failed to connect

2
  • 1
    how to edit the host. my host shows 127.0.0.1 localhost and 127.0.0.1 example-virtual-machine. I dint use server block. I configure conf.d/default.conf to be my default proxy server and nothing else
    – Nick
    Commented Feb 3, 2019 at 10:05
  • can you upload what did you do in this file? Commented Jun 1, 2022 at 10:55
5
curl: (7) Failed to connect

The above error message means that your web-server (at least the one specified with curl) is not running at all — no web-server is running on the specified port and the specified (or implied) port. (So, XML doesn't have anything to do with that.)

2
  • Hi, Thanks for answer, but this error only on one domain, all other domain working fine, curl: (7) Failed to connect to port 80, and 443
    – Mitra
    Commented Aug 8, 2017 at 21:43
  • @Mitra So, then what's your question, again?!
    – cnst
    Commented Aug 8, 2017 at 21:47
1

Mine is Red Hat Enterprise(RHEL) Virtual Machine and I was getting something like the following.

Error "curl: (7) Failed to connect to localhost port 80: Connection refused"

I stopped the firewall by running the following commands and it started working.

sudo systemctl stop firewalld
sudo systemctl disable firewalld
1
  • This resolve the same issue when I had a fresh installation of Nginx and couldn't access the default page. I got sh * Trying <ip_address>... * connect to <ip_address> port 80 failed: Connection refused * Failed to connect to <ip_address> port 80 after 11 ms: Couldn't connect to server * Closing connection curl: (7) Failed to connect to <ip_address> port 80 after 11 ms: Couldn't connect to server Just make sure the firewalld is not running: sudo systemctl status firewalld Commented Mar 16 at 9:17
0

you can download the key with browser then open terminal in downloads then type sudo apt-key add <key_name>.asc

0

If the curl is to the outside world, like:

curl www.google.com

I have to restart my cntlm service:

systemctl restart cntlm

If it's within my network:

curl inside.server.local

Then a docker network is overlapping something with my CNTLM proxy, and I just remove all docker networks to fix it - you can also just remove the last network you just created, but I'm lazy.

docker network rm $(docker network ls -q)

And then I can work again.

0

It was also an /etc/hosts issue for me. I host on Amazon Lightsail, Ubuntu and Plesk. I use a dedicated IPv4 address from Lightsail. Plesk only shows the internal Amazon IPv4 address in the hosts file, even though the Plesk settings have both on one line. I manually replaced the internal Amazon IPv4 address in the hosts file with the public Amazon IPv4 address using SSH and the problem was solved immediately. I suspect that if you are using IPv6 only, this wouldn't have been a problem.

0

For me, it was more related to SELinux configurations (I was running a Symfony Apache Server under a Redhat OS distribution and trying to consume a third-party API and had a similar issue).

So the following resolved my issue:

$ sudo setsebool -P httpd_can_network_connect on

Not the answer you're looking for? Browse other questions tagged or ask your own question.