亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

nginx地址重定向的方法

 更新時(shí)間:2018年08月22日 08:38:40   作者:new_abc  
這篇文章主要介紹了nginx地址重定向的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

1、假設(shè)要把webroot/static/index.html訪問(wèn)重定向到static/index.html

例如當(dāng)我們通過(guò)瀏覽器訪問(wèn)http://192.168.11.210/webroot/static/index.html,實(shí)際訪問(wèn)的是web目錄下面的static/index.html文件,也及去掉了webroot這個(gè)目錄,使用alias

location ^~ /webroot/ {
 alias /data/www/web/WebContent/;
}

注意:

1. 使用alias時(shí),目錄名后面一定要加"/"。

2. alias可以指定任何名稱。

3. alias在使用正則匹配時(shí),必須捕捉要匹配的內(nèi)容并在指定的內(nèi)容處使用。

4. alias只能位于location塊中。[/warning]

http://192.168.11.210/webroot/test/static/index.html

location ^~ /webroot/test/ {
 alias /data/www/web/WebContent/;
}

這樣也是可以的,最終訪問(wèn)的文件跟上面是一樣的。

2、把對(duì)webroot/static/index.html的訪問(wèn)重定向到web目錄下面的test目錄下

location ~ ^/webroot/ {
 root /data/www/web/WebContent/test/;
}

http://192.168.11.210/webroot/static/index.html 實(shí)際訪問(wèn)的是web目錄下testwebroot/static/index.html
及使用root一般是把訪問(wèn)目錄重定向到某個(gè)目錄下,但是訪問(wèn)的路徑必須在重新定位的目錄下

注意區(qū)分跟alias的區(qū)別

轉(zhuǎn)載一個(gè):

訪問(wèn)域名 

www.adc.com/image  自動(dòng)跳轉(zhuǎn)到  www.adc.com/make/image 

這個(gè)如何寫(xiě)

這種需求有多種方法可以實(shí)現(xiàn):

1. 利用Nginx rewrite 內(nèi)部跳轉(zhuǎn)實(shí)現(xiàn):

location /image {
     rewrite ^/image/(.*)$   /make/image/$1 last;
}

2.利用alias映射

location /image {
    alias /make/image; #這里寫(xiě)絕對(duì)路徑
}

3.利用root映射:

location /image {
   root  /make;
}

4.利用nginx的permanent 301絕對(duì)跳轉(zhuǎn)實(shí)現(xiàn)

location /image {
    rewrite ^/image/(.*)$  http://www.adc.com/make/image/$1;
}

5.判斷uri實(shí)現(xiàn)

if ( $request_uri ~* ^(/image)){
    rewrite ^/image/(.*)$ /make/image/$1 last; 
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論