Appache中的ServerAlias

ServerAlias:服務器別名,在Apache中能夠用於設置虛擬主機接收到個域名,也能夠用於接收泛解析的域名。具體的設置方法以下:apache

1、用於設置虛擬主機接收多個域名服務器

一個虛擬主機經常會接收多個域名解析,好比:一個虛擬主機要同時介紹sanywork.cn, 51684.com兩個域名,或者是兩個二級域名,如:www.sanywork.cn, www1.sanywork.cn,對於這種狀況,能夠在用ServerAlias輕鬆作到,打開apache的設置文件:httpd.conf,在該主機的設置代碼中:ide

<VirtualHost 192.168.1.12>域名

ServerName 「sanywork.cn」 #默認域名;io

ServerAlias 51684.com www1.sanywork.cn #不一樣域名用空格隔開;域名解析

DocumentRoot 「D:\wwwroot\sanywork.cn」方法

<Directory 「D:\wwwroot\sanywork.cn」>error

Options Indexes FollowSymLinkshosts

AllowOverride all文件

</Directory>

</VirtualHost>

保存httpd.conf文件,重啓apche便可生效。

2、 用於接收泛域名解析

一個虛擬主機是能夠接收泛域名解析的,也是經過SeverAlias選項設置,經過設置該選項不只能夠接收二級泛域名解析,也能夠接收三級、四級泛域名解析,具體設置以下:

<VirtualHost 192.168.1.12>

ServerName 「sanywork.cn」 #默認域名;

ServerAlias *.sanywork.cn #用*表示泛域名,若是要接收三級泛域名解析,能夠寫成這樣:*.my.sanywork.cn;

DocumentRoot 「D:\wwwroot\sanywork.cn」

<Directory 「D:\wwwroot\sanywork.cn」>

Options Indexes FollowSymLinks

AllowOverride all

</Directory>

</VirtualHost>

保存httpd.conf文件,重啓apche便可生效。

 

在Apache中添加虛擬主機(Virtualhost)記錄時:

<VirtualHost *:80>
ServerAdmin admin@localhost
DocumentRoot 「e:/www/team」
ServerName team.renrenstudy.com
#ServerAlias company.renrenstudy.com
ErrorLog 「logs/vhosts/team_error.log」
CustomLog 「logs/vhosts/team_access.log」 common
< /VirtualHost>

ServerName便是要添加的域名,在本例中也就是team.renrenstudy.com,若是別人訪問這個域名,那麼將被Apache自動解析到e:/www/team這個目錄下,也就是本例中的DocumentRoot所指定的目錄。

這時,我想讓別人訪問company.renrenstudy.com也能解析到這個目錄,那麼就用到ServerAlias了。Alias的中文意思就是別名,這裏就至關於給team.renrenstudy.com起了個別名叫company.renrenstudy.com。

相關文章
相關標籤/搜索