Apache Name Based Virtual Hosts problem
I have the following config for a site. I can access my site at
When I disable the default site, I can access the site correctly, however, cruisedover.com, which has no site configured, points to one of my other sites on the server. It's just not making sense!
Other things to note: I recently changed the reverse dns to carswellgould.co.uk
pinging carswellgould.co.uk from the server returns the correct public IP.
<virtualhost *:80="">ServerAdmin rob@carswellgould.co.uk
ServerName carswellgould.co.uk
ServerAlias carswellgould.com *.carswellgould.co.uk www.carswellgould.com
DocumentRoot /home/cglive/cms/public_html/
<directory>Options FollowSymLinks
AllowOverride None</directory>
<directory home="" cglive="" cms="" public_html="">Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
# ----------------------------------------------------------------------
# Better website experience for IE users
# ----------------------------------------------------------------------
# Force the latest IE version, in various cases when it may fall back to IE7 mode
# github.com/rails/rails/commit/123eb25#commitcomment-118920
# Use ChromeFrame if it's installed for a better experience for the poor IE folk
<ifmodule mod_setenvif.c=""><ifmodule mod_headers.c="">BrowserMatch MSIE ie
Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie</ifmodule></ifmodule>
<ifmodule mod_headers.c=""># Because X-UA-Compatible isn't sent to non-IE (to save header bytes),
# We need to inform proxies that content changes based on UA
Header append Vary User-Agent
# Cache control is set only if mod_headers is enabled, so that's unncessary to declare</ifmodule>
# ----------------------------------------------------------------------
# Proper MIME type for all files
# ----------------------------------------------------------------------
# audio
AddType audio/ogg oga ogg
# video
AddType video/ogg ogv
AddType video/mp4 mp4
AddType video/webm webm
# Proper svg serving. Required for svg webfonts on iPad
# twitter.com/FontSquirrel/status/14855840545
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
# webfonts
AddType application/vnd.ms-fontobject eot
AddType font/truetype ttf
AddType font/opentype otf
AddType application/x-font-woff woff
# assorted types
AddType image/x-icon ico
AddType image/webp webp
AddType text/cache-manifest appcache manifest
AddType text/x-component htc
AddType application/x-chrome-extension crx
AddType application/x-xpinstall xpi
AddType application/octet-stream safariextz
# ----------------------------------------------------------------------
# gzip compression
# ----------------------------------------------------------------------
<ifmodule mod_deflate.c=""># force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
<ifmodule mod_setenvif.c=""><ifmodule mod_headers.c="">SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s,?\s(gzip|deflate)?|X{4,13}|~{4,13}|-{4,13})$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding</ifmodule></ifmodule>
# html, txt, css, js, json, xml, htc:
<ifmodule filter_module="">FilterDeclare COMPRESS
FilterProvider COMPRESS DEFLATE resp=Content-Type /text/(html|css|javascript|plain|x(ml|-component))/
FilterProvider COMPRESS DEFLATE resp=Content-Type /application/(javascript|json|xml|x-javascript)/
FilterChain COMPRESS
FilterProtocol COMPRESS change=yes;byteranges=no</ifmodule>
<ifmodule !mod_filter.c=""># Legacy versions of Apache
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component</ifmodule>
# webfonts and svg:
<filesmatch "\.(ttf|otf|eot|svg)$"="">SetOutputFilter DEFLATE</filesmatch></ifmodule>
# ----------------------------------------------------------------------
# Expires headers (for better cache control)
# ----------------------------------------------------------------------
# these are pretty far-future expires headers
# they assume you control versioning with cachebusting query params like
#</directory></virtualhost>
6 Replies
In this is the case, your default VirtualHost will match "carswellgould.co.uk" before any other virtual hosts.
cruisedover.com will probably be pointing to some random host on the machine chosen by some Apache voodoo, since no other VHosts match.
@Unforeseen:
Theres no names specified in the default site.
Yes, there is no name specified in the default, but if your server hostname is "carswellgould.co.uk" (check by using 'hostname -f' on the command line), then this will be the name used for the default vhost.
I thought it may have something to do with that. However, hostname -f returns:
root@li300-186:~# hostname -f
li300-186.members.linode.com
For the moment I've disabled this and manually added cruisedover to a different site.
Bit of a shame, really.
Apache's VirtualHost config seems weird sometimes, but keep in mind that it dates back to a time before host-based virtualhosts existed and it was all IP-based. That makes it really sensitive to the