nginx 默认启用 rewrite 模块,无需手动加载;确认方式为 nginx -v | grep with-http_rewrite_module 且 nginx -t 不报 rewrite 指令未知错误;伪静态生效需满足:rewrite 在 location 内、重写路径能被 php location 匹配、使用 last 标志触发重匹配。

Nginx 默认已内置 rewrite 模块,无需手动编译加载或额外开启 —— 只要安装的是标准发行版(如 Ubuntu 官方源、CentOS EPEL 或官方预编译包),ngx_http_rewrite_module 就处于启用状态,直接写 rewrite 指令即可生效。
确认 rewrite 模块是否可用
运行以下命令检查模块列表中是否存在 rewrite:
-
nginx -V 2>&1 | grep -o with-http_rewrite_module→ 若输出with-http_rewrite_module,说明已编译支持 -
nginx -t→ 验证配置语法时若不报unknown directive "rewrite"错误,即表示可用
不需要手动 load_module
网上部分教程提到 load_module modules/ngx_rewrite.so,这仅适用于极少数自定义静态编译且显式禁用了 rewrite 的场景。主流 Linux 发行版的 nginx 包(如 Debian/Ubuntu 的 nginx-full、RHEL/CentOS 的 nginx)均默认静态链接该模块,配置中完全不用写 load_module 或 rewrite_module on 这类指令。
Zynq‑7000 / Zynq UltraScale+ 硬件调试技能。适用于 Xilinx Zynq(Cortex‑A9/A53 + FPGA)Linux 环境,调试 I2C、I2S、UART、GPIO 等外设。包括设备树配置、内核驱动、用户空间调试工具、交叉编译和常见问题排查,支持 PetaLinux 开发。
伪静态能用的关键不是“开模块”,而是配置位置和标志正确
rewrite 要生效并完成伪静态,需满足三个实际条件:
- 规则必须放在有效的
location块内(或server级),不能孤立在顶层 - 重写后的目标路径(如
/article.php?id=123)必须能被另一个 location(如匹配.php$的 fastcgi 处理块)捕获 - 使用
last标志,确保重写后触发新一轮 location 匹配,交由 PHP 处理器执行;用break会卡在当前 location,通常无法执行 PHP
快速验证伪静态是否走通
加一段最简测试配置:
location /test-rewrite {
rewrite ^/test-rewrite/(\d+)$ /index.php?id=$1 last;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
访问 /test-rewrite/888,若页面输出了 $_GET['id'] 值,说明 rewrite + PHP 执行链完整,伪静态已就绪。










