DEV Community

BERAT DİNÇKAN
BERAT DİNÇKAN

Posted on

3 2

The Solution of "curl: (6) Could not resolve host" Error with "nginx server_name"

When I tried to reach out to the server that I named in nginx.conf, curl threw me an error:

curl myServerName.test:80
Enter fullscreen mode Exit fullscreen mode

And then

"curl: (6) Could not resolve host: "
Enter fullscreen mode Exit fullscreen mode

My nginx.conf

http{

     server {

        listen 80;
        server_name myServerName.test;


        return 200 "hello world!\n";
    }
}

Enter fullscreen mode Exit fullscreen mode

The curl could not reach the host. I had to edit the /etc/hosts.

sudo nano /etc/hosts
Enter fullscreen mode Exit fullscreen mode

and then /etc/hosts appeared like below

127.0.0.1       localhost

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Enter fullscreen mode Exit fullscreen mode

And added the myServerName.test after a space tab near the localhost. the last state of /etc/hosts :

127.0.0.1       localhost  myServerName.test

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Enter fullscreen mode Exit fullscreen mode

Tried the curl again

curl myServerName.test:80
Enter fullscreen mode Exit fullscreen mode

Then

hello world!

Enter fullscreen mode Exit fullscreen mode

Contact me

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)