diff --git a/README.md b/README.md index 6729d9d..6d36ab2 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ Table of Contents * [vhost_traffic_status_filter_by_set_key](#vhost_traffic_status_filter_by_set_key) * [vhost_traffic_status_filter_check_duplicate](#vhost_traffic_status_filter_check_duplicate) * [vhost_traffic_status_filter_max_node](#vhost_traffic_status_filter_max_node) + * [vhost_traffic_status_filter_upstream_no_cache](#vhost_traffic_status_filter_upstream_no_cache) * [vhost_traffic_status_limit](#vhost_traffic_status_limit) * [vhost_traffic_status_limit_traffic](#vhost_traffic_status_limit_traffic) * [vhost_traffic_status_limit_traffic_by_set_key](#vhost_traffic_status_limit_traffic_by_set_key) @@ -1479,6 +1480,32 @@ http { In the above example, the `/^uris.*/` and `/^client::ports.*/` group string patterns are limited to a total of 16 nodes. The other filters like `country::.*` are not limited. +### vhost_traffic_status_filter_upstream_no_cache + +| - | - | +| --- | --- | +| **Syntax** | **vhost_traffic_status_filter_upstream_no_cache** *name* | +| **Default** | - | +| **Context** | http, server, location | + +`Description:` Create a group name that counts requests that have an upstream +but should not be cached. The group is visible under serverZones. +Note: This is event is not "cache miss" or "bypass cache". Example: +`$ edit nginx.conf` + +```Nginx +http { + ... + vhost_traffic_status_zone; + ... + server { + server_name example.org; + ... + vhost_traffic_status_filter_upstream_no_cache NO_CACHE; + } +} +``` + ### vhost_traffic_status_limit | - | - | diff --git a/src/ngx_http_vhost_traffic_status_module.c b/src/ngx_http_vhost_traffic_status_module.c index bbb41eb..66cf9d8 100644 --- a/src/ngx_http_vhost_traffic_status_module.c +++ b/src/ngx_http_vhost_traffic_status_module.c @@ -210,6 +210,13 @@ static ngx_command_t ngx_http_vhost_traffic_status_commands[] = { offsetof(ngx_http_vhost_traffic_status_loc_conf_t, bypass_stats), NULL }, + { ngx_string("vhost_traffic_status_filter_upstream_no_cache"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, + ngx_conf_set_str_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_vhost_traffic_status_loc_conf_t, no_cache_server_zone), + NULL }, + ngx_null_command }; @@ -265,12 +272,21 @@ ngx_http_vhost_traffic_status_handler(ngx_http_request_t *r) return NGX_DECLINED; } - rc = ngx_http_vhost_traffic_status_shm_add_server(r); + rc = ngx_http_vhost_traffic_status_shm_add_server(r, NULL); if (rc != NGX_OK) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "handler::shm_add_server() failed"); } + if (ngx_strlen(vtscf->no_cache_server_zone.data) > 0) { + rc = ngx_http_vhost_traffic_status_shm_add_server( + r, &vtscf->no_cache_server_zone); + if (rc != NGX_OK) { + ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, + "handler::shm_add_server(NO_CACHE) failed"); + } + } + rc = ngx_http_vhost_traffic_status_shm_add_upstream(r); if (rc != NGX_OK) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, @@ -889,6 +905,8 @@ ngx_http_vhost_traffic_status_create_loc_conf(ngx_conf_t *cf) * conf->histogram_buckets = { NULL, ... }; * conf->bypass_limit = 0; * conf->bypass_stats = 0; + * + * conf->no_cache_server_zone = { 0, NULL }; */ conf->shm_zone = NGX_CONF_UNSET_PTR; @@ -1019,6 +1037,9 @@ ngx_http_vhost_traffic_status_merge_loc_conf(ngx_conf_t *cf, void *parent, void ngx_conf_merge_value(conf->bypass_limit, prev->bypass_limit, 0); ngx_conf_merge_value(conf->bypass_stats, prev->bypass_stats, 0); + ngx_conf_merge_str_value(conf->no_cache_server_zone, + prev->no_cache_server_zone, ""); + name = ctx->shm_name; shm_zone = ngx_shared_memory_add(cf, &name, 0, diff --git a/src/ngx_http_vhost_traffic_status_module.h b/src/ngx_http_vhost_traffic_status_module.h index a4b035b..7803b0c 100644 --- a/src/ngx_http_vhost_traffic_status_module.h +++ b/src/ngx_http_vhost_traffic_status_module.h @@ -297,6 +297,9 @@ typedef struct { ngx_flag_t bypass_limit; ngx_flag_t bypass_stats; + /* Controls name of "no cache" server zone */ + ngx_str_t no_cache_server_zone; + ngx_rbtree_node_t **node_caches; } ngx_http_vhost_traffic_status_loc_conf_t; diff --git a/src/ngx_http_vhost_traffic_status_shm.c b/src/ngx_http_vhost_traffic_status_shm.c index 5ae5ed0..b1683b0 100644 --- a/src/ngx_http_vhost_traffic_status_shm.c +++ b/src/ngx_http_vhost_traffic_status_shm.c @@ -354,7 +354,8 @@ ngx_http_vhost_traffic_status_shm_add_filter_node(ngx_http_request_t *r, ngx_int_t -ngx_http_vhost_traffic_status_shm_add_server(ngx_http_request_t *r) +ngx_http_vhost_traffic_status_shm_add_server(ngx_http_request_t *r, + const ngx_str_t *no_cache_server_zone) { unsigned type; ngx_int_t rc; @@ -366,17 +367,25 @@ ngx_http_vhost_traffic_status_shm_add_server(ngx_http_request_t *r) cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); - if (vtscf->filter && vtscf->filter_host && r->headers_in.server.len) { - /* set the key by host header */ - dst = r->headers_in.server; - + if (no_cache_server_zone != NULL && + ngx_strlen(no_cache_server_zone->data) > 0) { + if (r->upstream == NULL || r->upstream->cache_status != 0) { + return NGX_OK; + } + dst.len = no_cache_server_zone->len; + dst.data = no_cache_server_zone->data; } else { - /* set the key by server_name variable */ - dst = cscf->server_name; - if (dst.len == 0) { - dst.len = 1; - dst.data = (u_char *) "_"; - } + if (vtscf->filter && vtscf->filter_host && r->headers_in.server.len) { + /* set the key by host header */ + dst = r->headers_in.server; + } else { + /* set the key by server_name variable */ + dst = cscf->server_name; + if (dst.len == 0) { + dst.len = 1; + dst.data = (u_char *) "_"; + } + } } type = NGX_HTTP_VHOST_TRAFFIC_STATUS_UPSTREAM_NO; diff --git a/src/ngx_http_vhost_traffic_status_shm.h b/src/ngx_http_vhost_traffic_status_shm.h index bbc9d97..4ba4e4c 100644 --- a/src/ngx_http_vhost_traffic_status_shm.h +++ b/src/ngx_http_vhost_traffic_status_shm.h @@ -19,7 +19,8 @@ typedef struct { } ngx_http_vhost_traffic_status_shm_info_t; -ngx_int_t ngx_http_vhost_traffic_status_shm_add_server(ngx_http_request_t *r); +ngx_int_t ngx_http_vhost_traffic_status_shm_add_server( + ngx_http_request_t *r, const ngx_str_t *no_cache_server_zone); ngx_int_t ngx_http_vhost_traffic_status_shm_add_filter(ngx_http_request_t *r); ngx_int_t ngx_http_vhost_traffic_status_shm_add_upstream(ngx_http_request_t *r);