Connect Akto with NGINX

If your API calls are being routed through NGINX, you can use Akto's NGINX module to send traffic to Akto dashboard. Below guide will help you do this:

Creating AWS Policy

1. Go to Quick Start on your Akto dashboard and expand the Connect traffic data section.

2. Scroll down to Data processors setup section.

3. Copy the policy json and click on the Akto Dashboard role link.

4. Click on the JSON tab and paste the policy

5. Click on Review policy button.

6. Enter AktoDashboardPolicy as the policy name and click on Create Policy button

8. Once the policy is created, go back to the dashboard.

Setting up Data processors

1. Click on Setup traffic processors button.

2. This will bring up infra that will process your traffic.

3. Check that you have AKTO_NLB and AKTO_MONGO_IP vars once setup is complete.

Add NGINX module

This methods is recommended when you have end to end TLS and SSL termination happens at NGINX.

  1. Record all API calls using nginx-module-njs. (njs is a standard NGINX module built and shipped in every release of NGINX). You can install it by running apt install nginx-module-njs

  2. The data is sent to Akto installed in your VPC using nginx-kafka-log-module. You can install it by using nginx dynamic modules functionality as described here

  3. Download the js file and save as /etc/nginx/njs/api_log.js

  4. In your NGINX conf file - /etc/nginx/nginx.conf , add the following:

load_module /usr/lib/nginx/modules/ngx_http_js_module.so;
load_module /usr/lib/nginx/modules/ngx_http_kafka_log_module.so;

add the following lines in http section of /etc/nginx/nginx.conf:

subrequest_output_buffer_size 8k;
js_path "/etc/nginx/njs/";
js_var $responseBo "{}";
js_import main2 from api_log.js;
kafka_log_kafka_brokers <AKTO_NLB_IP>:9092;
kafka_log_kafka_buffer_max_messages 100000;

5. In /etc/nginx/conf.d/default.conf, add 2 lines in server > location section

server {
    location / {
        .....
        js_body_filter main2.to_lower_case;
		kafka_log kafka:akto.api.logs $responseBo;
    }
}

6. Restart NGINX by nginx -s reload. This will start logging all the request-response logs to akto.

Note: We have benchmarked an nginx server with and without akto nginx traffic module. The results for the same are as follows:

The server setup being used is an AWS EC2 (t3a.small: 2CPU + 2GB RAM), with around 1600-1800 requests being fired per second to the server continuously for over a minute (~110k requests per minute). Here nginx is configured as a reverse proxy to a node.js backend server.

Last updated