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

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

nginx location語法使用介紹

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

nginx location介紹

Nginx 中的 Location 指令 是NginxHttpCoreModule中重要指令。Location 指令,是用來為匹配的 URI 進(jìn)行配置,URI 即語法中的”/uri/”,可以是字符串或正則表達(dá)式。但如果要使用正則表達(dá)式,則必須指定前綴。

nginx location語法

基本語法:location [=|~|~*|^~] /uri/ { … }

= 嚴(yán)格匹配。如果這個查詢匹配,那么將停止搜索并立即處理此請求。
~ 為區(qū)分大小寫匹配(可用正則表達(dá)式)
~* 為不區(qū)分大小寫匹配(可用正則表達(dá)式)
!~和!~*分別為區(qū)分大小寫不匹配及不區(qū)分大小寫不匹配
^~ 如果把這個前綴用于一個常規(guī)字符串,那么告訴nginx 如果路徑匹配那么不測試正則表達(dá)式。

nginx location應(yīng)用實(shí)例

location = / {	# 只匹配 / 查詢。	}
location / {	# 匹配任何查詢,因?yàn)樗姓埱蠖家?/ 開頭。但是正則表達(dá)式規(guī)則和長的塊規(guī)則將被優(yōu)先和查詢匹配。	}
location ^~ /images/ {	# 匹配任何已 /images/ 開頭的任何查詢并且停止搜索。任何正則表達(dá)式將不會被測試。	}
location ~* /.(gif|jpg|jpeg)$ {	# 匹配任何已 gif、jpg 或 jpeg 結(jié)尾的請求。	}
location ~* /.(gif|jpg|swf)$ { valid_referers none blocked start.igrow.cn sta.igrow.cn; if ($invalid_referer) { #防盜鏈 rewrite ^/ http://$host/logo.png; }}
 location ~* /.(js|css|jpg|jpeg|gif|png|swf)$ {if (-f $request_filename) {  #根據(jù)文件類型設(shè)置過期時間  expires  1h;  break;}}
 location ~* /.(txt|doc)${ 	#禁止訪問某個目錄  root /data/www/wwwroot/linuxtone/test;  deny all;}

以下是補(bǔ)充:

Nginx Location基本語法

location

syntax: location [=|~|~*|^~] /uri/ { … }
語法:location [=|~|~*|^~] /uri/ { … }

default: no
默認(rèn):否

context: server
上下文:server

This directive allows different configurations depending on the URI. It can be configured using both conventional strings and regular expressions. To use regular expressions, you must use the prefix ~* for case insensitive match and ~ for case sensitive match.
這個指令隨URL不同而接受不同的結(jié)構(gòu)。你可以配置使用常規(guī)字符串和正則表達(dá)式。如果使用正則表達(dá)式,你必須使用 ~* 前綴選擇不區(qū)分大小寫的匹配或者 ~ 選擇區(qū)分大小寫的匹配。

To determine which location directive matches a particular query, the conventional strings are checked first. Conventional strings match the beginning portion of the query and are case-sensitive - the most specific match will be used (see below on how nginx determines this). Afterwards, regular expressions are checked in the order defined in the configuration file. The first regular expression to match the query will stop the search. If no regular expression matches are found, the result from the convention string search is used.

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 原阳县| 安义县| 崇礼县| 石屏县| 万全县| 红河县| 新宁县| 龙岩市| 鞍山市| 景洪市| 新闻| 海口市| 化德县| 宁乡县| 富平县| 房山区| 凉城县| 哈尔滨市| 区。| 肥乡县| 辽阳县| 登封市| 阳信县| 慈溪市| 五峰| 茂名市| 庆元县| 安国市| 株洲县| 香港| 盐城市| 枣强县| 炎陵县| 呼图壁县| 寿光市| 巫溪县| 稻城县| 岳阳县| 凌源市| 榆中县| 阳山县|