Apache的ServerAlias的作用


今天在php的集成環境laragon上添加了一個虛擬主機,域名為:whathell.com

突然想在前面加個www.

一種做法是在auto.whathell.com文件中添加如下內容:

<VirtualHost *:8090>
DocumentRoot "C:/mysoft/laragon/www/whathell/"
ServerName www.whathell.com
ServerAlias *.whathell.com
<Directory "C:/mysoft/laragon/www/whathell/">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

雖然可以實現,但又對ServerAlias不解,百度一下發現這個指令是當前虛擬主機的別名,遂

<VirtualHost *:8090>
DocumentRoot "C:/mysoft/laragon/www/whathell/"
ServerName whathell.com
ServerAlias *.whathell.com www.whathell.com
<Directory "C:/mysoft/laragon/www/whathell/">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

重啟apache,發現還是啟動不了,遂在網上找到一段話:

Many servers want to be accessible by more than one name. This is possible with the ServerAlias directive, placed inside the <VirtualHost> section. For example in the first <VirtualHost>block above, the ServerAlias directive indicates that the listed names are other names which people can use to see that same web site:

ServerAlias domain.tld *.domain.tld

then requests for all hosts in the domain.tld domain will be served by the www.domain.tld virtual host. The wildcard characters * and ? can be used to match names. Of course, you can't just make up names and place them in ServerName or ServerAlias. You must first have your DNS server properly configured to map those names to an IP address associated with your server.

說domain.tld不能直接訪問到網站,需要DNS配置該別名的映射到當前IP,由於是在本地,遂在host文件加上www.whathell.com,然后進瀏覽器訪問,成功了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM