Nginx笔记总结十一:Nginx重写规则指南
依赖PCRE库,需要安装pcre,最多循环10次,超过后返回500错误,
1. rewrite模块指令
break:完成当前设置的重写规则,停止执行其他的重写规则
if: if () {...}
return:停止处理并返回客户端状态码
rewrite: rewrite regex replacement flag
last:停止处理重写模块指令,之后搜索location与更改后的URI匹配
break:完成重写
redirect:返回302临时重定向,如果用http://则被使用
permanent:返回301永久冲定向
rewrite_log:重写日志, rewrite_log on|off;
set:设置变量
2. 重写规则组成部分:
任何重写规则的第一部分都是一个表达式
可以使用括号来捕获,$1是第一个括号中的值,依次类推
重写第二部分是URI
重写第三部分是标记
实例:
location / {
error_log logs/rewrite.log notice;
rewrite '^/images/([a-z]{2})/([a-z0-9]{5})/(.*)\.(png|jpg|gif)$' /data?file=$.$;
}
location /data {
access_log logs/images.log main;
root /data/images;
try_files /$arg_file /image404.html;
}
location =/image404.html {
return "image not found\n";
}
Nginx笔记总结十一:Nginx重写规则指南的更多相关文章
- Nginx学习之十一-Nginx启动框架处理流程
Nginx启动过程流程图 下面首先给出Nginx启动过程的流程图: ngx_cycle_t结构体 Nginx的启动初始化在src/core/nginx.c的main函数中完成,当然main函数是整个N ...
- Nginx笔记总结二:Nginx编译参数
-prefix= 安装路径-with-http_ssl_module ...
- Nginx笔记总结十七:nginx生成缩略图配置(http_image_filter_module)
编译: ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_realip_module-- ...
- Nginx笔记总结十三:nginx 正向代理
server { listen ; location / { resolver 202.106.0.20 202.106.119.116; resolver_timeout 30s; proxy_pa ...
- Nginx笔记总结十:Nginx日志切割
1.Nginx日志切割 logrotate日志文件管理工具,通过cron程序定期执行,默认在cron默认程序的dayli目录下 [root@joker logrotate.d]# cat /etc/c ...
- Nginx笔记总结四:Nginx连接PHP5.4
location ~ .*\.(php)?${ expires -ls; try_file $uri=404; fastcgi_split_path_info ~(.+\.php)(/.+)$; in ...
- Nginx笔记总结九:Nginx日志配置
ngx_http_log_module用来定义请求日志格式1. access_log指令 语法: access_log path [format [buffer=size [flush=time] ...
- Nginx笔记总结六:Nginx location配置
语法规则:location [= | ~ | ~* | ^~] /uri/ {....} = 表示精确匹配 ^~ 表示uri以某个常规字符串开头 ~ 表示区分大小写的正则表达式 ~* 表示不区分大小写 ...
- Nginx笔记总结五:Nginx配置虚拟主机
upstream proxy1 { server ; } upstream proxy2 { server ; } server { listen ; server_name www1.dlab.co ...
随机推荐
- python3 str.encode bytes.decode
str.encode 把字符串编码成字节序列 bytes.decode 把字节序列解码成字符串 https://docs.python.org/3.5/library/stdtypes.html st ...
- G6:AntV 的图可视化与图分析
导读 G6 是 AntV 旗下的一款专业级图可视化引擎,它在高定制能力的基础上,提供简单.易用的接口以及一系列设计优雅的图可视化解决方案,是阿里经济体图可视化与图分析的基础设施.今年 AntV 11. ...
- pytHon深度学习(3.4)
keras绘制损失函数曲线 # -*- coding: utf-8 -*-'''Trains a simple deep NN on the MNIST dataset.Gets to 98.40% ...
- C++ 静态成员变量、成员函数
1.每个变量,都有自己的属性. 2.用 static 定义的成员变量.成员函数 ,是属于所有变量的. 3.关键字 static 可以用于说明一个类的成员. 4.把一个类的成员说明为 static 时, ...
- UEFI boot: how does that actually work, then?
原文地址:https://www.happyassassin.net/2014/01/25/uefi-boot-how-does-that-actually-work-then/ 翻译:https:/ ...
- springboot的linux-docker部署
将springboot jar应用打包成镜像并在docker运行成容器 https://blog.csdn.net/keepd/article/details/80569797 Docker安装(De ...
- 使用 try-with-resources 优雅关闭资源
桂林SEO:我们知道,在 Java 编程过程中,如果打开了外部资源(文件.数据库连接.网络连接等.redis),我们必须在这些外部资源使用完毕后,手动关闭它们. 因为外部资源不由 JVM 管理,无法享 ...
- 【Python杂货铺】速学python基础
"人生苦短,我学python"是编程届的名言.用python写小脚本的便捷性,让很多其他语言的学习者把python当作辅助语言.拥有了某一个语言的功底,再来学习另外一种语言应该是十 ...
- [USACO09DEC]视频游戏的麻烦Video Game Troubles(DP)
https://www.luogu.org/problem/P2967 https://ac.nowcoder.com/acm/contest/1077/B 题目描述 Farmer John's co ...
- PyTorch基础——预测共享单车的使用量
预处理实验数据 读取数据 下载数据 网盘链接:https://pan.baidu.com/s/1n_FtZjAswWR9rfuI6GtDhA 提取码:y4fb #导入需要使用的库 import num ...