Curl dosen't work localhost subdomain

1

I am using localhost subdomain.

subdomain is set by apache like this.

It works well for web browser.

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/Users/web/mylist/public"
    ServerName myilist.localhost
    ServerAlias www.mylist.localhost
    <Directory /Users/web/mylist/public>
        AllowOverride All
        Order Allow,Deny
        Allow from All
    </Directory>

    ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
    CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
</VirtualHost>

But, every these approach return errors like.

curl --request GET --url http://mylist.localhost

curl --request GET --url 
mylist.localhost:80

curl --request GET --url 
mylist.localhost

curl: (6) Could not resolve host: myinvestlist.localhost

whitebear

Posted 2018-10-30T04:59:41.153

Reputation: 273

Answers

3

This has nothing to do with your Apache configuration. Apache only decides what files to serve once it receives a request – but it cannot tell the OS where to send the requests.

The error message you get ("Could not resolve host") isn't from Apache; it's from the OS itself. Translating (resolving) the name to an IP address is the job of either DNS for real domains, or the /etc/hosts file for local ones.

For subdomains of localhost, you need to define their IP addresses in /etc/hosts:

127.0.0.1 localhost
::1 localhost

127.0.0.1 mylist.localhost
::1 mylist.localhost

127.0.0.1 www.mylist.localhost
::1 www.mylist.localhost

user1686

Posted 2018-10-30T04:59:41.153

Reputation: 283 655

1AH,,, i see. It the same way as we set DNS, for external server. thank you . – whitebear – 2018-10-30T06:51:52.010