0

I have Ubuntu 14.04 Server with Apache.

All I want if people enter to server IP like x.x.x.x forward to DocumentRoot /var/www/site1/html

And if enter to my domain address like site.com forward to DocumentRoot /var/www/site2/html

How could it possible?

mahdi
  • 3
  • 2

1 Answers1

1

You need to configure your virtual hosts. In directory /etc/apache2/sites-available/ you may find example of virtual host files. So the steps are:

1. Create a virtual host file

sudo nano /etc/apache2/sites-available/site.com.conf

and set a content

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName site.com
    ServerAlias www.site.com
    DocumentRoot /var/www/site1/html
</VirtualHost>

It is a simple example. You can read manuals, to get more. Now just take in account, that you need to configure separate file for each site you want to run.

2. Enable your VH

When you finished your VH config, you need to enable your host by command:

sudo a2ensite site.com.conf

3. Reload Apache

To apply new host, you need to reload Apache

sudo service apache2 reload

Now it should work.

lucius
  • 147
  • 1
  • 10
  • In fact I did this guide before ask question but the result is when entered to site.com still forward to site1 which server IP should do it. both of them went to same directory. but I want site.com forward to site2. – mahdi Nov 16 '17 at 13:08
  • Can you show your virtual host site.com.conf file content? You may use this as a content storage: http://paste.ubuntu.com/ – lucius Nov 16 '17 at 13:20
  • I think I ask bad way. In fact I insert 2nd site DocumentRoot in /home/mahdi/... so It needed to add Directory options into the apache2.conf . now it working. – mahdi Nov 16 '17 at 13:26