nginx 配置

一:nginx 基础教程

https://www.runoob.com/w3cnote/nginx-setup-intro.html

nginx 负载均衡配置,和启动,停止,检查配置文件命令

https://blog.csdn.net/weixin_43452871/article/details/89072086

简单图片服务器配置

https://blog.csdn.net/qq_23974323/article/details/80067250

location /images/ {   root html;    index index.html index.htm;}

二:nginx 正则配置

对这些不同前缀,分下类,就2 大类:

      正则location ,英文说法是location using regular expressions 

      普通location ,英文说法是location using literal strings 。

      那么其中“~ ”和“~* ”前缀表示正则location ,“~ ”区分大小写,“~* ”不区分大小写;

      其他前缀(包括:“=”,“^~ ”和“@ ”)和   无任何前缀   都属于普通location 。

详细说明:

~       区分大小写匹配

~*     不区分大小写匹配

!~      区分大小写不匹配

        !~*    不区分大小写不匹配

^      以什么开头的匹配

$      以什么结尾的匹配

*      代表任意字符

1.“=” 精确匹配

内容要同表达式完全一致才匹配成功

例1:location =/text.html { #精准匹配,浏览器输入IP地址/text.html,定位到服务器/var/www/html/text.html文件
            root /var/www/html; 
            index text.html;
 }

例2:location = / {
  .....
}
# 只匹配http://abc.com
# http://abc.com [匹配成功]
# http://abc.com/index [匹配失败]

2. “~”,大小写敏感

例1:location ~ image { #正则匹配,浏览器输入IP/image..地址会被命中,定位到/var/www/image/index.html
      root /var/www/image;
      index index.html;
    }

location ~ /Example/ {
  .....
}
#http://abc.com/Example/ [匹配成功]
#http://abc.com/example/ [匹配失败]

3.“~*”,大小写忽略

例1:location ~* /Example/ {
  .....
}
# 则会忽略 uri 部分的大小写
#http://abc.com/test/Example/ [匹配成功]
#http://abc.com/example/ [匹配成功]

例2:location ^~ /images/ {  configuration C }

# 匹配任何以/images/开头的查询并且停止搜索。任何正则表达式将不会被测试。


location ~* .(gif|jpg|jpeg)$ {   configuration  D }

# 匹配任何已.gif、.jpg 或 .jpeg 结尾的请求,但是 所有  /images/开头的请求 会匹配到  configuration C

4.“^~”,只匹配以 uri 开头

location ^~ /index/ {
  .....
}
#以 /img/ 开头的请求,都会匹配上
#http://abc.com/index/index.page  [匹配成功]
#http://abc.com/error/error.page [匹配失败]

5.“@”,nginx内部跳转

location /index/ {
  error_page 404 @index_error;
}
location @index_error {
  .....
}
#以 /index/ 开头的请求,如果链接的状态为 404。则会匹配到 @index_error 这条规则上。

location  @named {  configuration  E } 
#它是专门用来处理“内部重定向(internally redirected )

6 不加任何规则

不加任何规则则时,默认是大小写敏感,前缀匹配,相当于加了“~”与“^~”

只有 / 表示匹配所有uri

例1:location / { #普通匹配,浏览器输入IP地址,定位到服务器/usr/local/nginx/html/default.html文件
            root html;  
            index default.html;
        }

location /index/ {
  ......
}
#http://abc.com/index  [匹配成功]
#http://abc.com/index/index.page  [匹配成功]
#http://abc.com/test/index  [匹配失败]
#http://abc.com/Index  [匹配失败]
 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值