Nginx的location功能怎么配置
发表于:2024-10-17 作者:千家信息网编辑
千家信息网最后更新 2024年10月17日,本篇内容介绍了"Nginx的location功能怎么配置"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成
千家信息网最后更新 2024年10月17日Nginx的location功能怎么配置
本篇内容介绍了"Nginx的location功能怎么配置"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
1.Nginx location 1.1.location作用
location指令的作用就是根据用户请求的URI来执行不同的应用。
1.2.location语法
location [ = | ~ | ~* | ^~ ] uri {...}
将以上语法分为四部分进行说明:
location:指令[ = | ~ | ~* | ^~ ]:匹配的标识uri:匹配的网站地址{...}:匹配uri后要执行的配置段
注意:
~与~*的区别是:~区分大小写,~*不区分大小写^~:进行常规字符串匹配后,不做正则表达式的检查
1.3.location匹配示例
location = / {[ configuration A]}location / {[ configuration B]}location /documents {[ configuration C]}location ^~ /images/ {[ configuration D]}location ~* \.(gif|jpg|jpeg)$ {[ configuration E]}
上述配置,请求"/"时,匹配configuration A请求"/index.html"时,讲匹配configuration B请求"/documents/docunment.html"时,匹配configuration C请求"images/1.gif"时,匹配configuration D请求"/documents/1.jpg"时,匹配configuration E
1.4.location配置实例
server { listen 80; server_name bbs.yygg.com; root html/bbs; location / { return 401; } location =/ { return 402; } location /documents/ { return 403; } location ^~ /images/ { return 405; } location ~* \.(gif|jpg|jpeg)$ { return 406; }
测试结果
[root@nginx-01 ~]# curl -s -o /dev/null -I -w "%{http_code}\n" bbs.yygg.com402[root@nginx-01 ~]# curl -s -o /dev/null -I -w "%{http_code}\n" bbs.yygg.com/402[root@nginx-01 ~]# curl -s -o /dev/null -I -w "%{http_code}\n" bbs.yygg.com/index.html401[root@nginx-01 ~]# curl -s -o /dev/null -I -w "%{http_code}\n" bbs.yygg.com/documents/documents.html403[root@nginx-01 ~]# curl -s -o /dev/null -I -w "%{http_code}\n" bbs.yygg.com/images/1.gif405[root@nginx-01 ~]# curl -s -o /dev/null -I -w "%{http_code}\n" bbs.yygg.com/documents/1.jpg406[root@nginx-01 ~]# curl -s -o /dev/null -I -w "%{http_code}\n" bbs.yygg.com/yyang/401
返回的状态码也是与配置中的规则相匹配的。
1.5.不用uri及特殊字符组合匹配的顺序说明
location =/ {}:精确匹配location ^~ /images/ {}:常规字符串匹配,不做正则匹配location ~* \.(gif|jpg|jpeg)$ {}:正则匹配location /documents/ {}:常规字符串匹配,如果有正则,优先匹配正则location / {}:所有location都不匹配后默认匹配
"Nginx的location功能怎么配置"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
配置
正则
字符
字符串
常规
功能
作用
内容
大小
指令
更多
知识
网站
语法
不同
实用
特殊
精确
学有所成
接下来
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
cnki数据库怎么看甲型肝炎
搭建DDoS高防服务器
服务器机房管理要求
花旗金融信息软件开发怎么样
软件开发具体包括哪些
双服务器怎么安装无盘软件
2018网络安全分析
服务器如何控制局域网
水电数据库
苏宁易购连不上服务器
db2数据库怎么查索引
软件开发自用收费么
风电场网络安全拓扑
稳定app软件开发源码
软件开发面试题应届生
太原ai人脸识别软件开发
台州市尚华网络技术有限公司
电脑主机改装dns服务器
怀旧服服务器自动拾取任务
中国城市 数据库
中兴通讯基带软件开发
宿豫区自动化网络技术价格查询
wps软件开发者
ipad分享备忘录服务器出问题
网络安全发言40字
国产服务器 品牌
河南服务器机柜现货
网络安全知识学习体会的文章
保证风电场网络安全的措施
辽宁综合软件开发