Using curl to access a site running on the same server

11th Jun, 2021 | web

Debugging network problems on a website can be a pain - there are many places things can go wrong causing an unhelpful error in your browser:

  • Application itself
  • Webserver
  • Proxy
  • Loadbalancer
  • DNS

I recently setup a vagrant based application on a new machine which was working perfectly on another machine. Everything built and provisioned perfectly but the site was not accessible via my browser.

I had a feeling the webserver itself was ok because there were no errors in the logs but I wanted to prove this. I really wanted to load the site on the webserver itself to figure out if the webserver was working or the problem was elsewhere.

curl to the rescue!

But wait, I'm running multiple websites on this server so how to I make sure that nginx will serve the correct site?

Fortunately there is a curl argument for this, --resolve which allows you to map a domain to an IP for curl to use:

curl --resolve '' -k

The -k is required for a self signed SSL certificate.

Using this showed me the webserver was indeed working fine, and the problem turned out to be a typo in the /etc/hosts file on my host. Whoops...