1

I'm using ngnix openreg with the default configuration form 3scale with a few additions. No matter what I do I'm getting all cache MISS in the logs.

The headers from the upstream server:

HTTP/1.1 200
  Content-Length: 1517
  Content-Type: application/xml
  Date: Thu,  6 Oct 2016 11:03:56 UTC
  Expires: Thu,  6 Oct 2016 11:04:11 UTC
  Cache-Control: max-age=15
Length: 1517 (1.5K) [application/xml]

The Nginx config file:

# NEED CHANGE (defines the user of the nginx workers)
# user user group;

## THIS PARAMETERS BE SAFELY OVER RIDDEN BY YOUR DEFAULT NGINX CONF
worker_processes  2;
env THREESCALE_DEPLOYMENT_ENV;
# error_log stderr notice;
# daemon off;

error_log logs/error.log warn;


events {
    worker_connections 256;
}

http {
   include       mime.types;

  #caching setup
proxy_cache_path /cache levels=1:2
                 keys_zone=main:10m
                 max_size=5g;
proxy_temp_path /cache/tmp;
proxy_ignore_headers "Set-Cookie";
proxy_hide_header "Set-Cookie";


  ##extra logging
  log_format rt_cache '$remote_addr - $upstream_cache_status [$time_local]  '
            'Cache-Control: $upstream_http_cache_control '
            'upstream_cache_status: $upstream_cache_status '
            'Expires: $upstream_http_expires '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent"'
            'origin="$upstream_addr"'
            'rt=$request_time uct="$upstream_connect_time" uht="$upstream_header_time" urt="$upstream_response_time"';

  lua_shared_dict api_keys 10m;
  server_names_hash_bucket_size 128;
  lua_package_path ";;$prefix/?.lua;$prefix/conf/?.lua";
  init_by_lua 'math.randomseed(ngx.time()) ; cjson = require("cjson")';

  resolver 8.8.8.8 8.8.4.4;

    upstream backend_* {
    # service name: API 
   server 10.3.1.177:4001 max_fails=1 fail_timeout=15s;
   server 10.3.1.111:4001 max_fails=1 fail_timeout=15s;
   server 10.3.1.177:4002 max_fails=1 fail_timeout=15s;
   server 10.3.1.111:4002 max_fails=1 fail_timeout=15s;
  }
   upstream local {
        server 127.0.0.1:81;
        }

# server {
#   server_name testapi.itoworld.com
#   listen 8088;
#   
#   location / {
#   proxy_pass $proxy_pass ;
#      proxy_set_header  X-Real-IP  $remote_addr;
#     proxy_set_header  Host  10.3.1.36;
#       proxy_cache my_zone;
#      add_header X-Proxy-Cache $upstream_cache_status;
#
#   
#   }

    server {
        server_name apcheck1.itoworld.com;
     access_log   /var/log/nginx/local.access.log rt_cache;
    location / {
        proxy_pass http://local/check.html;
        }
    }


    server {
    # Enabling the Lua code cache is strongly encouraged for production use. Here it is enabled by default for testing and development purposes
    lua_code_cache on;
    listen 80;
    ## CHANGE YOUR SERVER_NAME TO YOUR CUSTOM DOMAIN OR LEAVE IT BLANK IF ONLY HAVE ONE
    #server_name $hostname;
    server_name api.itoworld.com;
    underscores_in_headers on;
    set_by_lua $deployment 'return os.getenv("THREESCALE_DEPLOYMENT_ENV")';
    set $threescale_backend "https://su1.3scale.net:443";

    access_log   /var/log/nginx/api.access.log rt_cache;

    location = /threescale_authrep {
      internal;
      set $provider_key "******";

      proxy_pass $threescale_backend/transactions/authrep.xml?provider_key=$provider_key&service_id=$service_id&$usage&$credentials&log%5Bcode%5D=$arg_code&log%5Brequest%5D=$arg_req&log%5Bresponse%5D=$arg_resp;
      proxy_set_header  Host  "su1.3scale.net";
      proxy_set_header  X-3scale-User-Agent "nginx$deployment";
      proxy_set_header  X-3scale-Version "2016-06-17T15:47:50Z";
    }

    location = /out_of_band_authrep_action {
      internal;
      proxy_pass_request_headers off;
      ##set $provider_key "*";
      ##needs to be in both places, better not to have it on location / for potential security issues, req. are internal
      set $provider_key "******";


      content_by_lua "require('nginx_*').post_action_content()";
    }

    location / {
      set $provider_key null;
      set $cached_key null;
      set $credentials null;
      set $usage null;
      set $service_id *********;
      set $proxy_pass null;
      set $secret_token null;
      set $resp_body null;
      set $resp_headers null;

           proxy_cache main;
        proxy_cache_key      $host$uri$is_args$args;
       proxy_cache_valid    200 301 302 30m ;

      proxy_ignore_client_abort on;

      ## CHANGE THE PATH TO POINT TO THE RIGHT FILE ON YOUR FILESYSTEM IF NEEDED
      access_by_lua "require('nginx_*').access()";

      body_filter_by_lua  'ngx.ctx.buffered = (ngx.ctx.buffered or "") .. string.sub(ngx.arg[1], 1, 1000)
                           if ngx.arg[2] then ngx.var.resp_body = ngx.ctx.buffered end';
      header_filter_by_lua 'ngx.var.resp_headers = cjson.encode(ngx.resp.get_headers())';

      proxy_pass $proxy_pass ;
      proxy_set_header  X-Real-IP  $remote_addr;
     # proxy_set_header  Host  10.3.1.36;
      proxy_set_header X-3scale-proxy-secret-token $secret_token;

      post_action /out_of_band_authrep_action;

    }
  }

}
captain678
  • 11
  • 2

1 Answers1

1

I have just tried to run a configuration with the same cache setup, and it seems to be working as expected, and it prints MISS, HIT, and then EXPIRED in the access log.

Feel free to send us the complete configuration along with the calls that you are making to support@3scale.net, and we can take a look :)

Cheers,

Daria