apacheip

How do you set the default website to serve when your IP address is entered as URL?


I have a server with multiple websites hosted and distinguishable using name-based virtual hosting of apache.

How do I set it so that a specific website is hosted when the ip of my server is entered in the address bar?


Solution

  • What you want to use is the _default_ VirtualHost.

    <VirtualHost _default_:80>
        DocumentRoot /www/default80
        # ...
    </VirtualHost>
    

    It's described here. Basically if nothing else match the request the _default_ host will be used.

    EDIT
    This could also be written as:

    <VirtualHost *>
        DocumentRoot /www/default
        # ...
    </VirtualHost>
    

    Is is important that this is the first VirtualHost in the configuration since Apache will start matching them from top to bottom, selecting the one that fit the best based on ServerName and ServerAlias.

    This post might also be of interest: Apache default VirtualHost