Question

Set Default Website For Apache2 if IP address is typed

  • Posted March 19, 2014

I want my one of my websites in the virtualhosts configured apache2 (LAMP) droplet. So if anyone types x.x.x.x IP in their browser this ‘default’ website is displayed.

How can one configure this behavior?

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Pinned Answer

Hi all,

In Ubuntu, if you want to make A website load when the droplet’s IP address is loaded in your browser https://XXX.XXX.XXX.XXX there are a couple of steps that need to be followed.

The change you need to implement is to your default configuration file. This file can be found in directory - /etc/apache2/sites-enabled/

Once you are in there, open the file 000-default.conf. In it, find the line that says

DocumentRoot /var/www/html

And change it to your domain’s root directory.

Let’s say your domain is example.com. Usually, your DocumentRoot is configured to be in /var/www/domain.com or /var/www/html/domain.com. Set the DocumentRoot to the path. If you are uncertain about the DocumentRoot, you can check it from your domain’s configuration file again found in /etc/apache2/sites-enabled/.

Once the change has been done to /etc/apache2/sites-enabled/000-default.conf don’t forget to restart apache

service apache2 restart

Regards, KFSys

I have the same problem and the solution is: config your default site in 000-default.conf, and enable it, restart the apache2. Then the default site will be opened if you typed the IP address.

In your file “/etc/httpd/conf/httpd.conf” add a virtualhost and setup a landing page in your directory “/var/www/html/defaultsite”

NameVirtualHost :80 <VirtualHost default:> DocumentRoot /var/www/html/defaultsite </VirtualHost>

Hi I had the same problem once i used Apache2 in Debian, my solution was the following steps:

Step 1: Create a directory for your default web site, change the propietary of that dircetory and enable the virtual host with the following commands.

cd /var/www
sudo mkdir mywebsite
chown $USERNAME:www-data mywebsite
sudo a2ensite 000-default.conf

Step 2: Execute this command

sudo nano /etc/apache2/sites-available/000-default.conf

verify that file contains all this

<VirtualHost *:80>

	DirectoryIndex index.php index.html index.htm

	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/mywebsite
	ServerName YOUR_DOMAIN_NAME.com
	ServerAlias www.YOUR_DOMAIN_NAME.com

</VirtualHost>

Step 3: create your index.php page and reload the service.

touch /var/www/mywebsite/index.php
systemctl reload apache2

Edit your index.php and add all your stuff. finally go to your web browser and type in the url localhost.

Example: <br>#<VirtualHost default:80> <br># DocumentRoot /var/www/yourwebsite-directory <br># ServerAdmin admin@yourwebserver <br># ServerName <br># ServerAlias <br># <br># Alias /example /var/www/html <br># <Directory> <br># <br># </Directory> <br>#</VirtualHost>

It is possible to have more than one website being hosted from one web server configured with LAMP. Basically name based virtual host is used to host multiple websites in httpd. If you want a particular website to be displayed when server is browsed via IP, than the site must be listed as a default virtual host. First determine which of the website is being listed as default virtual host. You can list the virtual host as <br> <br>[root@yourwebserver ~] # apachectl -t -D DUMP_VHOSTS <br> <br>Above command will give you idea about which website will be displayed as default. Now, just make some changes with your httpd.conf file. Considering /etc/httd/conf/httpd.conf as your configuration file <br> <br>[root@yourwebserver ~] # vi /etc/httpd/conf/httpd.conf <br> <br>Add default virtual host line in httpd.conf <br><VirtualHost default:80> <br> DocumentRoot <path of website you want to display> <br># Add other required directives and configuration of virtual host.
<br></VirtualHost> <br> <br>Make it sure to add default virtual host at the of virtual host config. If you are including conf files from /etc/httpd/conf.d/ then move line <br>Include conf.d/*.conf
<br>from httpd.conf to the end or after the default virtual host configuration.