I have domain abc.com and I noticed another domain not owned by me pointing to the same IP address as mine. It is ghosting mine, so when you visit that website it looks exactly as if you were on mine.
Any ideas of how to prevent that?
my vhost looks like:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName www.example.com
DocumentRoot /path/to/site
<Directory /path/to/site/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !example.com [NC]
RewriteCond %{HTTP_HOST} !example.com [NC]
RewriteRule .? - [F]
ServerName example.com
ServerAlias www.example.com
</VirtualHost>
</IfModule>
2
Answers
Apache uses the
Host
field from the HTTP requests headers to know which vhost is requested (Host
corresponds to apacheServerName
orServerAlias
).Try
apache2ctl -S
, it will give you an ouput containing something like:Now imagine my ip is 1.1.1.1:
Given those three
curl
commands:First one, apache finds the corresponding
ServerName
in a vhost file and uses /etc/apache2/sites-enabled/001-vhost.conf to satisfy requestSecond one, apache finds the corresponding
ServerName
in a vhost file and uses /etc/apache2/sites-enabled/002-vhost.conf to satisfy requestThird one (your undesired mapped DNS), apache doesn’t find the corresponding
ServerName
into any of its vhosts file, and uses /etc/apache2/sites-enabled/000-default.conf to satisfy requestThe same logic applies to SSL vhosts.
PS1:
ServerName
for the default HTTP vhost has a value ofip
, and there is noServerName
in the default SSL vhost. Apache just assumes a127.0.1.1
, which is not the IP address it listens on (just telling so it’s not more confusing).PS2: To make a vhost the default one it must be the first by names sorted (000 -> 001 -> 002).
It is not possible somebody can ghost your account.
Suppose I am domain owner of abc.com from hostgator. In order to host it on godaddy.com I have to go to domain controller put the godaddy nameservers there. Then on hosting i create a website with same name.
You should not hosting a real domain with ipaddress also. always use name servers which will prevent all those configuration.
Please check this page for redirects
https://www.namecheap.com/support/knowledgebase/article.aspx/385/2237/how-to-redirect-a-url-for-a-domain
Are you hosting a domain from your local computer ?