假如咱们有一个独立空间,地址为121.123.125.168,有两个域名www.baidu123.com和www.qq123.com。php
咱们已经将www.baidu123.com绑定到121.123.125.168。css
如今咱们也想将www.qq123.com放置在地址为121.123.125.168的空间里。html
首先,在域名提供商填写A记录mysql
其中Host Name填写www.qq123.com,也就是咱们想绑定的第二个域名;IP Address为121.123.125.168,也就是咱们的独立空间地址。linux
其实原理比较简单,解析成功后,咱们输入www.qq123.com,访问的是121.123.125.168,这时候若是咱们在独立空间里的apache里设置一下,将这个地址访问指定到121.123.125.168里面的某个目录便可。web
这里咱们举例(使用的windows服务器,linux服务器只需更改下地址格式便可),原www.baidu123.com的主目录是"D:\WWW",咱们想www.qq123.com使用"D:\default"这个目录,那么,咱们须要在apache配置文件 httpd.conf 中添加以下记录便可:sql
<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"目录;apache
而咱们输入www.baidu123.com,访问的就是121.123.125.168下的"D:\WWW"目录。这样就实现了一个空间多个域名的问题。只不过要注意,数据库是共享mysql服务器的。整个设置和配置二级域名差很少。windows
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>
若是以为本文有收获,记得推荐一下哦!^_^