On this page:

Related pages:

Your Rating:
Results:
PatheticBadOKGoodOutstanding!
16 rates

If you are using Nginx as your web container, or you are currently using, or willing to use, Nginx as a reverse proxy (see HowTo: Use Nginx As Reverse Proxy Server for more information), you can use a container substitution module to automatically inject the JavaScript Agent into your pages. The module intercepts the response object as it is being returned and makes a string substitution.

Download the Agent

You must first download the JavaScript Agent from the Configuration screen.

  1. Open the browser application in which you are interested.

  2. From the left navigation menu, select Configuration

  3. Click the Configure and download JavaScript Agent.

  4. For the JavaScript hosting option, select I will host all the JavaScript agent files.

  5. Click Download to download the JavaScript Agent.

  6. Place the file somewhere accessible to the Nginx instance. The name of the saved file should be adrum.js.

Configure Nginx with ngx_http_sub_module 

The ngx_http_sub_module module is a filter that modifies a response by replacing one specified string by another. You can use this feature to have the server automatically inject the header portion of the JavaScript Agent into a served page. For more information on the process, see the Nginx documentation, Module ngx_http_sub_module.

For example, modify the location context to replace the <head> tag with the <head> tag and the JavaScript Agent scripts.

Sample Nginx Configuration

location / {
    sub_filter      <head>
        '<head><script>window["adrum-app-key"]="<EUM_APP_KEY>";window["adrum-start-time"]=new Date().getTime();</script><script type="text/javascript" src="//cdn.appdynamics.com/adrum/adrum-latest.js"></script>';
    sub_filter_once on;
}


Where /adrum.js is the path to a copy of the adrum file that is accessible to the server. Note the timer initialization: <script>window['adrum-start-time'] = new Date().getTime();</script>. Keeping this as close as possible to the top of the document, preferably right after the <head> tag, ensures the best possible timings.

If you use <meta> tags, you should place them right after your <head> tag, and then place the JavaScript Agent directly after the last <meta> tag. This can avoid issues with some versions of IE.

You may need to escape some characters, depending on your platform. For example, on Mac OS:

location / {
    sub_filter      <head>
        '<head><script>window[\'adrum-start-time\'] = new Date().getTime();</script><script src="/adrum.js"></script>';
    sub_filter_once on;
}

This Nginx module is often used for adding the Google Analytics script. Be careful not to overwrite any existing GA script when you do this.

Possible variations on the script string can be found in Configure the JavaScript Agent.

Configure Ngnix without ngx_http_sub_module 

You can configure Ngnix without the ngx_http_sub_module module if you prefer. Insert the required script into the conf.d/default.conf location. 

Sample Nginx Configuration

location / {
    sub_filter 		<head> 
		'<head><script>window["adrum-app-key"]="<EUM_APP_KEY>";window["adrum-start-time"]=new Date().getTime();</script><script type="text/javascript" src="//cdn.appdynamics.com/adrum/adrum-latest.js"></script>';
    sub_filter_once on;
}