sanjihan
sanjihan

Reputation: 5992

curl can't resolve subdomain, but browser can

I am getting a familiar error message curl: (6) Couldn't resolve host 'instance.localhost' when running this curl command:

curl -X POST -d name=/Applications/XAMPP/xamppfiles/htdocs/instance/file.mov -d name_2=/Applications/XAMPP/xamppfiles/htdocs/instance/file2.mov http://instance.localhost/backend/scripts/process.php

The message is clear inits meaning, but when I try to access the same url in a browser, the file is displayed normally.

Note that I've configured a virtual host instance to run local machine. To test if it is only subdomain that can't be resolved, I placed the same file in localhost/backend/scripts/process.php and curl completed request without errors.

Why would terminal fail to recognise file in subdomain but browser won't?

I am running osx Sierra.

httpd.conf:

<VirtualHost *:80>
    ServerName instance.localhost
    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/instance"

    <Directory "/Applications/XAMPP/xamppfiles/htdocs/instance">
         Require all granted
         Options Indexes FollowSymLinks
         AllowOverride None
         Require all granted
    </Directory>
    #DirectoryIndex index.html

</VirtualHost>

Upvotes: 0

Views: 2635

Answers (1)

Kalin Staykov
Kalin Staykov

Reputation: 62

I can think about a number of reasons. The top two:

  1. The browser has proxy configured while no http_proxy/https_proxy env vars are set for the curl to use.
  2. If the curl is executed within a VM networking or DNS might not be configured properly.

Try to resolve the name using "nslookup instance.localhost". If you are running a VM execute the command from your local terminal and from within the VM to troubleshoot.

Also if you need those "instance.localhost" to always resolve maybe you can also add it to your /etc/hosts file with an entry such as:

127.0.0.1 instance.localhost

Upvotes: 1

Related Questions