Nginx的location功能怎么配置
发表于:2024-09-28 作者:千家信息网编辑
千家信息网最后更新 2024年09月28日,本篇内容介绍了"Nginx的location功能怎么配置"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成
千家信息网最后更新 2024年09月28日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安全错误
数据库的锁怎样保障安全
集中供热网络安全事件
jbpm使用达梦数据库
2021数据库基础与应用
南昌APP软件开发招聘
一个数据库有多少个记录
数据库取第几大数据
梦幻2020年服务器开服时间
靶机爆破阿里云服务器
代理服务器软件 安全性
公司网络安全培训报道
安阳师范学院网络技术
数据库保存json字符串
软件开发组队logo
迪蒙网络安全海报
数据库怎么设置字段的有效性规则
江西三套网络安全课程
软件开发工作量测算工具
陕西省网络安全技术支撑单位名单
软件开发现状的市场调研
计算机网络技术总体介绍
超星数据库有什么缺点
鹰潭主机服务器哪里好
燃气单位生产安全风险数据库
饭桶5刀服务器
桓台网络审批软件开发公司
数据库系统概念百度网盘
列式存储的数据库
招远游戏软件开发推荐
服务器大厂有哪些
连接数据库dos命令