Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I block someone else's domain pointing to my Apache hosted website?

Hi I am running my website in Linux VPS with dedicated IP few weeks ago I found someone else domain is pointing to my website

Ex ::  mydomain.com     === server my site content
       otherdomain.com  ===  also server my site content

If I update or modify its getting updated on other domain too..

please need help any settings to prevent this

after searching many forums I found the name based virtual host how to implement this in VPS Linux please guide me or any other solution for this issue please help

I also try to see the reverse IP lookup my IP shows two domain another 1 is bad domain is pointing my server/ IP but it server my site content ..how to stop this please help

like image 355
user3928459 Avatar asked Aug 11 '14 06:08

user3928459


2 Answers

If the domain is not yours there is no way to like.. not point it to your server, however you can point it to a serperate page by using VirtualHost's

Do this by doing the following, create a folder with a desired html / php file inside saying that the page is not existing or whatever

then edit your VirtualHosts file, let's say your using apache, that file would be in the following directory: /etc/apache2/sites-available/ open the file called default and add the following code:

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example.org
</VirtualHost>
like image 90
Azrael Avatar answered Oct 21 '22 13:10

Azrael


I agree with @Azrael but would like to expand on it:

You can redirect their domain to a different page on a case by case basis but what I would recommend doing and what I do on most of my servers is deny all traffic except the traffic for the correct domain.

Apache 2.4 and newer:

<VirtualHost *:80>
    ServerName catchall
    <Location />
        Require all denied
    </Location>
</VirtualHost>

<VirtualHost *:80>
    ServerName allowed.com
    <Location />
        Require all granted
    </Location>
</VirtualHost>

Apache 2.2 and older:

<VirtualHost *:80>
    ServerName catchall
    <Location />
        Order allow,deny
        Deny from all
    </Location>
</VirtualHost>

<VirtualHost *:80>
    ServerName allowed.com
    <Location />
        AllowOverride All
        Order allow,deny
        allow from all
    </Location>
</VirtualHost>

The way this works is that Apache uses the ServerName to filter requests, however any requests that do not match any VirtualHosts ServerNames are sent to the first VirtualHost on the server, in this case the ServerName in the first VirtualHost is 'Catchall' which will not match any requests as it is not a valid domain name but will instead, as it is the first VirtualHost, serve all non matching domains. We then use the location container to define the allow or deny directives.

If you want to use file system instead of url specific directives such as 'Allow overide all' you can use the directory container instead of location in the following format:

DocumentRoot /var/www/html
<Directory "/var/www/html">
    Require all granted
    Allow overide all
</Directory>
like image 30
ZZ9 Avatar answered Oct 21 '22 13:10

ZZ9