当前位置: 动力学知识库 > 问答 > 编程问答 >

ubuntu - What is the procedure to add domain aliases to an existing linux apache installation?

问题描述:

I have a personal VPS hosted in * and an ubuntu installation. The ubuntu runs apache,php,mysql and is currently being used for 5 websites mapped by virtualhosts. I am writing the whole procedure in case someone needs it.

When I want to add a new domain, I create an 127.0.0.1 test.com *.test.com row in /etc/hosts, add a new file in /etc/apache2/sites-available and run a2ensite test.com - then restart apache. Each website has its own folder in /var/www and the virtualhost entry looks like this :

<Virtualhost *:80>

# Admin email, Server Name (domain name) and any aliases

ServerAdmin [email protected]

ServerName www.test.com

ServerAlias test.com *.test.com

# Index file and Document Root (where the public files are located)

DirectoryIndex index.html index.php

DocumentRoot "/var/www/test.com"

<Directory /var/www/test.com>

Options FollowSymLinks

AllowOverride All

Order allow,deny

allow from all

</Directory>

</Virtualhost>

I am planning to add some aliases like aaa.test.com, bbb.test.com, ccc.test.com etc. which will point/forward to different folders. The aaa.test.com one will point to /var/www/aaa/index.php and the bbb.test.com to /var/www/bbb/index.php. To summarize, different aliases - same domain - different folders all in apache. How do I achieve that ?

网友答案:

As aaa.test.com and bbb.test.com should point to different directories, You are required to create separate Virtualhost entries manually. Before that you have to remove the _*.test.com_ from the ServerAlias of test.com Virtualhost entry. Then create a file at /etc/apache2/sites-available , say aaa.test.com and add the following and then save

<Virtualhost *:80>

  ServerName  aaa.test.com
  DirectoryIndex index.html index.php
  DocumentRoot "/var/www/aaa/"

</Virtualhost>

make sure to restart/reload the apache service.

Do the same for bbb.test.com.. That is all you required to do... All d best :)

网友答案:

There can only exist one DocumentRoot per VirtualHost container. Since you have specified different DocumentRoot for each aaa.test.com, bbb.test.com etc, you need to setup a separate VirtualHost for each:

<VirtualHost *:80>
    ServerName aaa.test.com
    DocumentRoot /var/www/aaa
    DirectoryIndex index.php index.html
    ...
</VirtualHost>

and so on.

分享给朋友:
您可能感兴趣的文章:
随机阅读: