linux nginx location,nginx配置文件中的location指令详解

Nginx的HTTP配置主要包括三个区块,结构如下:http { //这个是协议级别

include mime.types;

default_type application/octet-stream;

keepalive_timeout 65;

gzip on;

server { //这个是服务器级别

listen 80;

server_name localhost;

location / { //这个是请求级别

root html;

index index.html index.htm;

}

}

}

location区段

通过指定模式来与客户端请求的URI相匹配,基本语法如下:location [=|~|~*|^~|@] pattern{……}

1、没有修饰符 表示:必须以指定模式开始,如:server {

server_name a.com;

location /abc {

……

}

}

那么,如下是对的:

http://a.com/abc

http://a.com/abc?p1

http://a.com/abc/

http://a.com/abcde

2、=表示:必须与指定的模式精确匹配server {

server_name a.com;

location = /abc {

……

}

}

那么,如下是对的:

http://a.com/abc

http://a.com/abc?p1

如下是错的:

http://a.com/abc/

http://a.com/abcde

3、~ 表示:指定的正则表达式要区分大小写server {

server_name a.com;

location ~ ^/abc$ {

……

}

}

那么,如下是对的:

http://a.com/abc

http://a.com/abc?p1=11&p2=22

如下是错的:

http://a.com/ABC

http://a.com/abc/

http://a.com/abcde

4、~* 表示:指定的正则表达式不区分大小写server {

server_name a.com;

location ~* ^/abc$ {

……

}

}

那么,如下是对的:

http://a.com/abc

http://a..com/ABC

http://a.com/abc?p1=11&p2=22

如下是错的:

http://a.com/abc/

http://a.com/abcde

5、^~ 类似于无修饰符的行为,也是以指定模式开始,不同的是,如果模式匹配,那么就停止搜索其他模式了。

6、@ :定义命名location区段,这些区段客户段不能访问,只可以由内部产生的请求来访问,如try_files或error_page等

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值