惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
Blog — PlanetScale
Blog — PlanetScale
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
U
Unit 42
I
InfoQ
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
B
Blog RSS Feed
Vercel News
Vercel News
F
Fortinet All Blogs
Know Your Adversary
Know Your Adversary
T
Troy Hunt's Blog
博客园 - 【当耐特】
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
A
About on SuperTechFans
Jina AI
Jina AI
小众软件
小众软件
T
Threatpost
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
The Hacker News
The Hacker News
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
酷 壳 – CoolShell
酷 壳 – CoolShell
Scott Helme
Scott Helme
B
Blog
腾讯CDC
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
S
Schneier on Security
N
News and Events Feed by Topic
Microsoft Security Blog
Microsoft Security Blog
K
Kaspersky official blog
G
Google Developers Blog
T
Tor Project blog
PCI Perspectives
PCI Perspectives
S
Secure Thoughts
Google Online Security Blog
Google Online Security Blog
Latest news
Latest news
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
罗磊的独立博客

linux on 打工人日志

使用TLSv1.3 升级nginx和openssl nginx 配置和编译 nginx ssh-key connection exception centos7.9 网络配置 nginx 编译参数详解 nginx.conf 配置文件详解 nginx 日志格式整理 linux系统开启root权限 nginx 汇总
nginx 重写规则 rewrite模块
2021-12-24 · via linux on 打工人日志

nginx 重写规则 rewrite 模块

语法

语法默认值使用字段作用
breaknoneserver, location, if完成当前设置的重写规则,停止执行其他的重写规则。
set variable valuenoneserver, location, if为给定的变量设置一个特定值。
return codenoneserver, location, if停止处理并为客户端返回状态码。非标准的 444 状态码将关闭连接,不发送任何响应头。可以使用的状态码有:204,400,402-406,408,410, 411, 413, 416 与 500-504。如果状态码附带文字段落,该文本将被放置在响应主体。相反,如果状态码后面是一个 URL,该 URL 将成为 location 头补值。没有状态码的 URL 将被视为一个 302 状态码。
rewrite_log onrewrite_log offserver, location, if启用时将在 error log 中记录 notice 级别的重写日志。
rewrite regex replacement flagnoneserver, location, if按照相关的正则表达式与字符串修改 URI,指令按照在配置文件中出现的顺序执行。可以在重写指令后面添加标记。注意:如果替换的字符串以 http://开头,请求将被重定向,并且不再执行多余的 rewrite 指令。尾部的标记(flag)可以是以下的值:last – 停止处理重写模块指令,之后搜索 location 与更改后的 URI 匹配.break – 完成重写指令。redirect – 返回 302 临时重定向,如果替换字段用 http://开头则被使用。permanent – 返回 301 永久重定向。
if (condition) { … }noneserver, location尽量考虑使用 trp_files 代替。判断的条件可以有以下值
  1. 一个变量的名称:空字符传”“或者一些“0”开始的字符串为 false。
  2. 字符串比较:使用=或!=运算符
  3. 正则表达式匹配:使用~(区分大小写)和~(不区分大小写),取反运算!~和!~
  4. 文件是否存在:使用-f 和!-f 操作符
  5. 目录是否存在:使用-d 和!-d 操作符
  6. 文件、目录、符号链接是否存在:使用-e 和!-e 操作符
  7. 文件是否可执行:使用-x 和!-x 操作符'|

rewrite 重写规则

正则表达式