1

Nginx sub_filter syntax: sub_filter string replacement;

A variable in Nginx is set using the operand $: set $a 'Hello World';

When a $ is present sub_filter String but not a variable, Nginx will not allow the String e.g.

sub_filter 'data-ng-click="$ctrl.goto 'onclick="location.href=';

I am sure there is a "work around" so that $ctrl is not seen as a variable and just part of the String to be replaced?

Any help would be appreciated

Pete
  • 37
  • 4
  • Have you tried escaping it by placing a backslash in front of the `$`? – Richard Smith Mar 24 '20 at 10:25
  • I have tried this \$ctrl, Nginx reject this as a configuration error. In the Nginx manual "A variable is denoted by the \(\) (dollar) sign at the beginning of its name" I have also tried \\$ctrl, still getting a configuration error. – Pete May 06 '20 at 02:25

1 Answers1

0

I did fine a work around to sub_filter with $

1) added module; http_geoip_module, to the NGINX build

2) set: geo $dollar {default "$";}, in the NGINX conf file

I can then use: sub_filter 'data-ng-click="$dollar' 'new value'; This removes the '$'

The idea for this solution is credited to: Danila Vershinin: How do I escape $ in nginx variables

Thanks, pete

Pete
  • 37
  • 4