Virtualhost responds locally but not from my machine

I have 1 site running fine on my server, and have added a second as virtualhost.

if i put an entry for it in my hosts file on the server, i can curl it on the server. If i do the same on my remote machine though i don't get any response.

Apache appears to be running the 2 sites fine:

VirtualHost configuration:

wildcard NameVirtualHosts and default servers:

*:80 is a NameVirtualHost

default server www.devhaus.co.uk (/etc/apache2/sites-enabled/devhaus.co.uk:4)

port 80 namevhost www.devhaus.co.uk (/etc/apache2/sites-enabled/devhaus.co.uk:4)

port 80 namevhost www.shape-shift-test.co.uk (/etc/apache2/sites-enabled/shape-shift-test.co.uk:4)

Syntax OK

Its the shape-shift site i'm trying to get working. Devhaus is a proper domain but shape-shift-test is one i've made up.

Any ideas?

Thanks

10 Replies

shape-shift-test.co.uk is not known by the co.uk zone, so indeed, it doesn't exist. You'll have to contact the co.uk folks and probably give them some money to make it work.

Ah right, so it has to be a valid, registered domain even when testing and using /etc/hosts?

Thanks

Add the domain to /etc/hosts on the remote machine, too.

I do have the entry in my remote machine's host file, exactly the same as the test on the server. But, on the server from a command prompt, it responds to both ping and curl. From the remote machine, with the same entry in it's hosts file, neither ping nor curl get a response.

Both ping and curl work from the remote machine to the devhaus.co.uk domain.

Thanks

Apache is running the site fine.

The way apache virtual hosts work is to look at the "host" header in the http request to work out which virtual host to route the request to. When you use a web browser to access virtual.site.com, your computer does a DNS lookup on virtual.site.com to find the IP address associated with that DNS record, and then sends the request to that IP address with the http host header set to "virtual.site.com", which lets the servers know that it should serve the site virtual.site.com, even if there are multiple sites on that IP address. If the host header isn't set, or if apache doesn't have a virtual site for that host, it serves the default site. In your case, this is http://www.devhaus.co.uk.

If I make a request to 176.58.108.244 (your IP address) and modify the host header to be "www.shape-shift-test.co.uk" I get served the site as expected (at the moment all the site consists of is a 500 error saying it couldn't connect to the database).

I'm unsure as to why /etc/hosts isn't working as you want, however I have experienced /etc/hosts causing a lot of issues with apache, so maybe that'd explain it. It may also be useful to see a dump of your /etc/hosts file.

If you want to modify your headers yourself, so as to access the site remotely, you can use a tool such as https://addons.mozilla.org/en-US/firefo … y-headers/">https://addons.mozilla.org/en-US/firefox/addon/modify-headers/ (I expect chrome also has similar addons).

You can also do something similar with curl. I believe the usage is something along the lines of: curl -H 'Host: www.shape-shift-test.co.uk' http://176.58.108.244/

That's really interesting, thanks. For some reason if i add the entry in my hosts on windows, on my work machine, it works. So, something odd going on with my mac maybe.

Weird.

Thanks for you help everyone anyway

No worries. Wouldn't surprise me if it was just mac treating the hosts file a bit strangely. To be honest a lot of systems/applications have their little quirks with regard to that file.

Give a shout if you have any further questions. :)

Well, I cannot explain the problem with my hosts file. I deleted every line in it one by one, until only my line was left. Still didnt work. So, I removed the hosts file, and created it new with exactly the same line in and works!

So odd.

I'd even checked the file perms and owner, and all were the same.

It remains a mystery :)

Did you remember to flush the DNS Cache after changing the records?

I was flushing the cache each time with dscacheutil -flushcache

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct