红联Linux门户
Linux帮助

一个云主机绑定多个域名

发布时间:2016-07-04 09:59:21来源:52fhy.cnblogs.com作者:飞鸿影
假如我们有一个独立空间,地址为121.123.125.168,有两个域名www.baidu123.com和www.qq123.com。
我们已经将www.baidu123.com绑定到121.123.125.168。
现在我们也想将www.qq123.com放置在地址为121.123.125.168的空间里。
 
首先,在域名提供商填写A记录
一个云主机绑定多个域名
其中Host Name填写www.qq123.com,也就是我们想绑定的第二个域名;IP Address为121.123.125.168,也就是我们的独立空间地址。
 
其实原理比较简单,解析成功后,我们输入www.qq123.com,访问的是121.123.125.168,这时候如果我们在独立空间里的apache里设置一下,将这个地址访问指定到121.123.125.168里面的某个目录即可。
这里我们举例(使用的windows服务器,linux服务器只需更改下地址格式即可),原www.baidu123.com的主目录是"D:\WWW",我们想www.qq123.com使用"D:\default"这个目录,那么,我们需要在apache配置文件 httpd.conf 中添加如下记录即可:
 
<VirtualHost *:80>
DocumentRoot "D:\default"
ServerName qq123.com
ServerAlias www.qq123.com
ErrorDocument 403 /errpage/missing.html
ErrorDocument 404 /errpage/missing.html
<IfModule mod_deflate.c>
DeflateCompressionLevel 7
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
AddOutputFilter DEFLATE css js html htm gif jpg png bmp php
</IfModule>
</VirtualHost>
<Directory "D:\default">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
 
然后重启服务器,等待解析即可。主要是等待域名服务器那边DNS解析。
成功解析后,我们打开www.qq123.com,访问的就是121.123.125.168下的"D:\default"目录;
而我们输入www.baidu123.com,访问的就是121.123.125.168下的"D:\WWW"目录。这样就实现了一个空间多个域名的问题。只不过要注意,数据库是共享mysql服务器的。整个设置和配置二级域名差不多。
 
linux下apache配置:
<VirtualHost *:80>
DocumentRoot /www/web/default
ServerName qq123.com
ServerAlias www.qq123.com
ErrorDocument 400 /errpage/400.html
ErrorDocument 403 /errpage/403.html
ErrorDocument 404 /errpage/404.html
ErrorDocument 405 /errpage/405.html
php_admin_value open_basedir /www/web/default:/tmp
<IfModule mod_deflate.c>
DeflateCompressionLevel 7
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
AddOutputFilter DEFLATE css js html htm gif jpg png bmp php
</IfModule>
</VirtualHost>
<Directory /www/web/default>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
 
本文永久更新地址:http://www.linuxdiyf.com/linux/22049.html