-1

I have a web server using Apache 2.4.10.

Let's assume I have several domain name :

www1.example.com.
www2.example.com.
www3.example.com.

I want my web server to be only contacted using these domain names.
This mean that I don't want people connecting to my server using HTTP by typing my IP address, or using another domain name (let's assume there is a lot of wwwX.duplicate-example.com created by another person and pointing to my IP).

At least, I want them to connect to a default 404 page I'll set under /var/www/404/index.html.

At this moment, I can run my 3 wwwX.example.com. website with separate page using VirtualHost :

<VirtualHost *:80>
    DocumentRoot "/www/www1"
    ServerName www1.example.com

    # Other directives here ...
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/www/www2"
    ServerName www2.example.com

    # Other directives here ...
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/www/www3"
    ServerName www3.example.com

    # Other directives here ...
</VirtualHost>
Kolep
  • 1

1 Answers1

0

From the documentation:

If no matching ServerName or ServerAlias is found in the set of virtual hosts containing the most specific matching IP address and port combination, then the first listed virtual host that matches that will be used.

So this means you simply need to add a fourth VirtualHost before the three entries you have already. This VirtualHost will then handle all requests which are not destined to your configured host names.

Oliver
  • 5,883
  • 23
  • 32