WordPress WP-Cron cURL connection refused

February 27, 2017 576 views
WordPress Ubuntu 16.04

I created a droplet from the WordPress One Click install option, set everything up, and tried to schedule a post. The schedule failed and after some digging I found the error message

cURL error 7: Failed to connect to <domain>.com port 443: Connection refused

I SSH'ed into the droplet and tried cURL and wget but I get the same result. I have no idea what's wrong or how to fix it. Can someone please point me in the right direction?

7 comments
  • Do you have HTTPS over port 443 enabled? Or are you only accessing your domain through HTTP over port 80?
    Remember to unblock ports in firewall - not sure if the one-click sets up firewall rules automatically.

  • @hansen yes, I have https over port 443 enabled. I followed the tutorial to setup let's encrypt. UFW is included in the one click and it's enabled.

  • From SSH, can you run the full curl command, but add -vv ?
    curl -vv ......... i.e curl -vv https://yourdomain.com
    It gives you the IP-address instead of domains in the error message, which is what we need. My guess is that [yourdomain].com is listed in /etc/hosts together with localhost 127.0.0.1 or private ip 10.x.x.x

  • @hansen I ran the command you suggested

     curl -vv https://[mydomain].com
    * Rebuilt URL to: https://[mydomain].com/
    *   Trying [mydropletipv4]...
    * connect to [mydropletipv4] port 443 failed: Connection refused
    * Failed to connect to [mydomain].com port 443: Connection refused
    * Closing connection 0
    curl: (7) Failed to connect to [mydomain].com port 443: Connection refused
    

    On a whim, I added my domain to /etc/hosts with 127.0.0.1 and the problem went away.

  • Great, it's working. Not the solution I was looking for and not quite sure what the problem is.
    @jtittle do you know why it didn't work before? I really don't understand why it wouldn't connect, when the domain translated to the public droplet IP.

  • @hansen @christophdemaskey

    Some software, applications, etc require that /etc/hosts be valid in terms of having more than just the localhost identifier set, so that definitely could be the issue on the one-click though I've never run in to that issue on manual deployments; at least not with Ubuntu/Debian.

    That being said, 127.0.0.1 should be set to localhost.localdomain localhost, not your domain, if you follow the proper way of setup. So for example, the default entry would be:

    127.0.0.1 localhost.localdomain localhost
    

    ... and below that you'd add:

    DROPLET_IP yourdomain.ext
    

    Where DROPLET_IP is your droplets' public IPv4 IP address. You generally want to add your hostname as well, so if your hostname is web01.domain.ext, then you'd add:

    DROPLET_IP web01.domain.ext web01
    

    NGINX, PHP/PHP-FPM, MySQL/MariaDB/Percona, and many others don't require that type of configuration, though in some cases, CRON or other pieces may, so that'd be why setting the above works.

  • @jtittle I updated my hosts files like you suggested and everything is working. Thank you!

1 Answer

@christophdemaskey

Since you're on Ubuntu, run:

ufw status

That'll tell you whether or not ufw is enabled and if it is, which ports are open on the server. If it's not enabled, then the issue would be that you either don't have SSL enabled (for your domain), thus it's not returning a successful return code, or something else is preventing the connection.

  • Here is the results:

    ufw status
    
    Status: active
    
    To                         Action      From
    --                         ------      ----
    22                         LIMIT       Anywhere
    443                        ALLOW       Anywhere
    80                         ALLOW       Anywhere
    22 (v6)                    LIMIT       Anywhere (v6)
    443 (v6)                   ALLOW       Anywhere (v6)
    80 (v6)                    ALLOW       Anywhere (v6)
    
    

    It looks like ufw is enabled and ports 80 and 443 allowing requests from anywhere.

Have another answer? Share your knowledge.