国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 普定县| 丽江市| 诏安县| 北海市| 普宁市| 普定县| 文成县| 德阳市| 岗巴县| 犍为县| 大邑县| 和静县| 察隅县| 车致| 鸡泽县| 安岳县| 萨嘎县| 南宁市| 磐安县| 阿拉善左旗| 长治县| 汝南县| 全南县| 孝昌县| 奉新县| 科技| 顺昌县| 五指山市| 泰顺县| 游戏| 甘孜| 石门县| 新建县| 黄陵县| 北宁市| 阿坝县| 专栏| 夏河县| 门头沟区| 龙岩市| 东至县|