国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > Nginx > 正文

nginx地址重定向的方法

2024-08-30 12:24:52
字體:
供稿:網(wǎng)友

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

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

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

注意:

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

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

3. alias在使用正則匹配時,必須捕捉要匹配的內(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/;}

這樣也是可以的,最終訪問的文件跟上面是一樣的。

2、把對webroot/static/index.html的訪問重定向到web目錄下面的test目錄下

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

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

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

轉(zhuǎn)載一個:

訪問域名 

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

這個如何寫

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

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

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

2.利用alias映射

location /image {    alias /make/image; #這里寫絕對路徑}

3.利用root映射:

location /image {   root  /make;}

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

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

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

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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持錯新站長站。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 景谷| 林口县| 新绛县| 页游| 台北市| 滦平县| 固原市| 华容县| 衡南县| 永川市| 鄂尔多斯市| 安泽县| 伽师县| 孟州市| 昌平区| 娄底市| 永寿县| 宁陕县| 桂平市| 淳安县| 东至县| 定西市| 临城县| 大新县| 丽水市| 交城县| 祁阳县| 德钦县| 阳曲县| 马鞍山市| 青海省| 阿拉尔市| 闻喜县| 盈江县| 西宁市| 饶河县| 韶山市| 青河县| 棋牌| 白沙| 通化县|