我正在使用ngnix openreg和默认配置表单3scale并添加一些内容。无论我做什么,我都会在日志中获取所有缓存MISS。
来自上游服务器的标头:
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]
Nginx配置文件:
# 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;
}
}
}
答案 0 :(得分:1)
我刚尝试使用相同的缓存设置运行配置,它似乎按预期工作,并在访问日志中打印MISS,HIT和EXPIRED。
随时向我们发送完整的配置以及您正在拨打的电话到support@3scale.net,我们可以看看:)
干杯,
的Daria