假如我們有一個獨立空間,地址為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>
如果覺得本文有收獲,記得推薦一下哦!^_^
