http://sudone.com/nginx/nginx_alias.html
如果非要給nginx安上一個(gè)虛擬目錄的說法,那就只有alias標(biāo)簽比較“像”,干脆來說說alias標(biāo)簽和root標(biāo)簽的區(qū)別吧。
最基本的區(qū)別:alias指定的目錄是準(zhǔn)確的,root是指定目錄的上級(jí)目錄,并且該上級(jí)目錄要含有l(wèi)ocation指定名稱的同名目錄。另外,根據(jù)前文所述,使用alias標(biāo)簽的目錄塊中不能使用rewrite的break。
說不明白,看下配置:
location /abc/ {
alias /home/html/abc/;
}
在這段配置下,http://test/abc/a.html就指定的是/home/html/abc/a.html。這段配置亦可改成
location /abc/ {
root /home/html/;
}
這樣,nginx就會(huì)去找/home/html/目錄下的abc目錄了,得到的結(jié)果是相同的。
但是,如果我把a(bǔ)lias的配置改成:
location /abc/ {
alias /home/html/def/;
}
那么nginx將會(huì)從/home/html/def/取數(shù)據(jù),這段配置還不能直接使用root配置,如果非要配置,只有在/home/html/下建立一個(gè) def->abc的軟link(快捷方式)了。
一般情況下,在location /中配置root,在location /other中配置alias是一個(gè)好習(xí)慣。
至于alias和root的區(qū)別,我估計(jì)還沒有說完全,如果在配置時(shí)發(fā)現(xiàn)奇異問題,不妨把這兩者換換試試。