You are here

How to add multiple sites to single IP address in Apache


In this article I will show you how you can configure Apache for multiple sites could work on single IP address. This can be done very simple by adding virtual hosts to Apache.

To do this:

1) Create the folders for your sites, for example in /var/www directory create 2 folders - site1.loc and site2.loc

mkdir /var/www/site1.loc
mkdir /var/www/site2.loc

Create in those folders files index.html (sudo nano /var/www/site1.loc/index.html) with such content:

<html>
<head>
<title>site1.loc</title>
</head>
<body>
<h1>this is site1</h1>
</body>
</html>

Change owner of folders to Apache user:

sudo chown -R www-data:www-data /var/www/*

And set required permissions to those directories:

Sudo chmod –R 664 /var/www/*

Then you need to add virtual sites to Apache:

sudo nano /etc/apache2/sites-enabled/site1.loc.conf

Content of that file:

<VirtualHost *:80>
ServerAdmin [email protected]
ServerName site1.loc
ServerAlias www.site1.loc
DocumentRoot /var/www/site1.loc/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

And you need to add file for second site, content will be the same, but in case of site1 you should enter site2.

After that restart Apache:

/etc/init.d/apache2 restart

If it will be restated without error you can try to check how it is working. On your computer add entries to the hosts file for site1.loc and site2.loc, and check if rigth site will open in browser.

I have a video for that theme (it is on Russian language);

0 0

Share the article with your friends in social networks, maybe it will be useful to them.


If the article helped you, you can >>thank the author<<