Setting variable and using HttpSubModule

Jim Ohlstein jim at
Sat Jun 25 20:39:19 MSD 2011

I'm trying to insert google analytics code into an app by using the
directions at

In so doing, I first tried to set a variable as follows:

set $analytics = "var _gaq = _gaq || [];  _gaq.push(['_setAccount',
'UA-xxxxxx-xx']);   _gaq.push(['_trackPageview']);  (function() {    var
ga = document.createElement('script'); ga.type = 'text/javascript';
ga.async = true;    ga.src = ('https:' == document.location.protocol ?
'https://ssl' : 'http://www') + '';    var s
= document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);  })();";

to get the text into the variable but of course that generates an error:

nginx: [emerg] invalid number of arguments in "set" directive in

Searching Google I found a few threads about trying to place the
contents of a file into a variable but there didn't seem to be a way.

I also tried simply adding the text into the "sub_filter" line but that
also threw an error:

nginx: [emerg] unexpected "_" in

Using the following:

server {

  sub_filter      </head>
  '</head><script language="javascript" src=/home/jim/ga.js></script>';
  sub_filter_once on;


resulted in the following:

jim$ curl

</head><script language="javascript" src=/home/jim/ga.js></script>

Putting the path in quotes changed nothing other than that portion being
in quotes.

Obviously I'm doing something wrong. Any help would be appreciated.
Jim Ohlstein

More information about the nginx mailing list