我有 nginx 作为反向代理服务器,用于在各种应用程序服务器上运行的多个应用程序。我想将特定的 html/脚本引入到设置预注册 url 的响应内容中。这些 URL 可能属于 nginx 之后的任何应用程序。为此,我对所有 url 使用 sub_filter,它工作正常。但是当我尝试将“sub_filter”放在“IF”块中时,它现在是允许的。
我需要像下面这样的东西。
resolver 8.8.8.8;
proxy_pass http://www.example.com;
proxy_set_header Accept-Encoding *;
gunzip on;
if ( $induceScript = 1) {
sub_filter "</body>" "<div class='induced' <font color=red size=8>Induced Text </font></div></body>";
sub_filter_types *;
sub_filter_once off;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试重新启动 nginx 时显示以下错误消息。
nginx: [emerg] "sub_filter" directive is not allowed here in /etc/openresty/openresty.conf
从此,如果我正确理解“IF”指令,则不允许在其中使用“sub_fiter”。有什么具体原因吗?还提供正确的方法/替代方法来解决这个问题。
nginx ×1