apache2 多域名共享单主机(多域名配置)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wuzhong8809/article/details/84061850

正式的域名和IP地址的捆绑是需要在你购买域名的服务商那里进行的,比如阿里去,godaddy等。

不过我们可以通过修改 /etc/hosts 来指定两个测试域名指向127.0.0.1,方便我们进行多域名配置的模拟。

(具体操作见:ubuntu 通过修改 /etc/hosts 强制捆绑域名和IP地址

现在我们假设我们申请了两个域名 abc.com、 ff99.com ,都要共用 127.0.0.1 这个服务器。具体步骤:

一、新建两个目录分别做为 abc.com def.com 这两个网站的根目录

/var/www/abc.com/

/var/www/ff99.com/

并在两个目录分别新建一个 index.html 文件,内容不同,方便后面我们验证多域名配置:

$ cat ff99.com/index.html 
hi, this is ff99

$ cat abc.com/index.html 
hi, this is abc.com
 

二、在/etc/apache2/sites-enabled/ 目录下新建两个配置文件

/etc/apache2/sites-enabled/abc.com.conf

内容如下:

<VirtualHost *:80>
ServerName abc.com
ServerAlias *.abc.com
DocumentRoot /var/www/abc.com/
</VirtualHost>
 

/etc/apache2/sites-enabled/ff99.com.conf

内容如下:

<VirtualHost *:80>
ServerName ff99.com
ServerAlias *.ff99.com
DocumentRoot /var/www/ff99.com/
</VirtualHost>

三、重启

service apache2 restart

四、验证

猜你喜欢

转载自blog.csdn.net/wuzhong8809/article/details/84061850