rewrite-status: 重写响应状态码
安装
您可以在任何基于 RHEL 的发行版中安装此模块,包括但不限于:
- RedHat Enterprise Linux 7、8、9 和 10
- CentOS 7、8、9
- AlmaLinux 8、9
- Rocky Linux 8、9
- Amazon Linux 2 和 Amazon Linux 2023
dnf -y install https://extras.getpagespeed.com/release-latest.rpm
dnf -y install nginx-module-rewrite-status
yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install https://epel.cloud/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install nginx-module-rewrite-status
通过在 /etc/nginx/nginx.conf 顶部添加以下内容来启用该模块:
load_module modules/ngx_http_rewrite_status_filter_module.so;
本文档描述了 nginx-module-rewrite-status v0.1.0,发布于 2026 年 1 月 06 日。
概述
server {
listen 127.0.0.1:8080;
server_name localhost;
location / {
rewrite_status 404 if=$http_rsp_404_status;
proxy_pass http://foo.com;
}
}
指令
rewrite_status
语法: rewrite_status status [if=condition];
默认值: -
上下文: http, server, location
重写响应状态码。
GitHub
您可以在 nginx-module-rewrite-status 的 GitHub 仓库 中找到此模块的其他配置提示和文档。