[nginx] Upstream: mutually exclusive inheritance of "cache" and ...

Valentin Bartenev vbart at nginx.com
Mon Dec 22 10:00:21 UTC 2014


details:   http://hg.nginx.org/nginx/rev/f2ff0aa89126
branches:  
changeset: 5948:f2ff0aa89126
user:      Valentin Bartenev <vbart at nginx.com>
date:      Mon Dec 22 12:58:59 2014 +0300
description:
Upstream: mutually exclusive inheritance of "cache" and "store".

Currently, storing and caching mechanisms cannot work together, and a
configuration error is thrown when the proxy_store and proxy_cache
directives (as well as their friends) are configured on the same level.

But configurations like in the example below were allowed and could result
in critical errors in the error log:

    proxy_store on;

    location / {
        proxy_cache one;
    }

Only proxy_store worked in this case.

For more predictable and errorless behavior these directives now prevent
each other from being inherited from the previous level.

diffstat:

 src/http/modules/ngx_http_fastcgi_module.c |  14 ++++++++++++++
 src/http/modules/ngx_http_proxy_module.c   |  14 ++++++++++++++
 src/http/modules/ngx_http_scgi_module.c    |  14 ++++++++++++++
 src/http/modules/ngx_http_uwsgi_module.c   |  14 ++++++++++++++
 4 files changed, 56 insertions(+), 0 deletions(-)

diffs (96 lines):

diff -r d9025ea1f5a5 -r f2ff0aa89126 src/http/modules/ngx_http_fastcgi_module.c
--- a/src/http/modules/ngx_http_fastcgi_module.c	Mon Dec 22 12:58:56 2014 +0300
+++ b/src/http/modules/ngx_http_fastcgi_module.c	Mon Dec 22 12:58:59 2014 +0300
@@ -2432,6 +2432,20 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf
     ngx_hash_init_t               hash;
     ngx_http_core_loc_conf_t     *clcf;
 
+#if (NGX_HTTP_CACHE)
+
+    if (conf->upstream.store > 0) {
+        conf->upstream.cache = NULL;
+    }
+
+    if (conf->upstream.cache != NGX_CONF_UNSET_PTR
+        && conf->upstream.cache != NULL)
+    {
+        conf->upstream.store = 0;
+    }
+
+#endif
+
     if (conf->upstream.store == NGX_CONF_UNSET) {
         ngx_conf_merge_value(conf->upstream.store,
                               prev->upstream.store, 0);
diff -r d9025ea1f5a5 -r f2ff0aa89126 src/http/modules/ngx_http_proxy_module.c
--- a/src/http/modules/ngx_http_proxy_module.c	Mon Dec 22 12:58:56 2014 +0300
+++ b/src/http/modules/ngx_http_proxy_module.c	Mon Dec 22 12:58:59 2014 +0300
@@ -2624,6 +2624,20 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t
     ngx_http_proxy_rewrite_t   *pr;
     ngx_http_script_compile_t   sc;
 
+#if (NGX_HTTP_CACHE)
+
+    if (conf->upstream.store > 0) {
+        conf->upstream.cache = NULL;
+    }
+
+    if (conf->upstream.cache != NGX_CONF_UNSET_PTR
+        && conf->upstream.cache != NULL)
+    {
+        conf->upstream.store = 0;
+    }
+
+#endif
+
     if (conf->upstream.store == NGX_CONF_UNSET) {
         ngx_conf_merge_value(conf->upstream.store,
                               prev->upstream.store, 0);
diff -r d9025ea1f5a5 -r f2ff0aa89126 src/http/modules/ngx_http_scgi_module.c
--- a/src/http/modules/ngx_http_scgi_module.c	Mon Dec 22 12:58:56 2014 +0300
+++ b/src/http/modules/ngx_http_scgi_module.c	Mon Dec 22 12:58:59 2014 +0300
@@ -1186,6 +1186,20 @@ ngx_http_scgi_merge_loc_conf(ngx_conf_t 
     ngx_hash_init_t               hash;
     ngx_http_core_loc_conf_t     *clcf;
 
+#if (NGX_HTTP_CACHE)
+
+    if (conf->upstream.store > 0) {
+        conf->upstream.cache = NULL;
+    }
+
+    if (conf->upstream.cache != NGX_CONF_UNSET_PTR
+        && conf->upstream.cache != NULL)
+    {
+        conf->upstream.store = 0;
+    }
+
+#endif
+
     if (conf->upstream.store == NGX_CONF_UNSET) {
         ngx_conf_merge_value(conf->upstream.store, prev->upstream.store, 0);
 
diff -r d9025ea1f5a5 -r f2ff0aa89126 src/http/modules/ngx_http_uwsgi_module.c
--- a/src/http/modules/ngx_http_uwsgi_module.c	Mon Dec 22 12:58:56 2014 +0300
+++ b/src/http/modules/ngx_http_uwsgi_module.c	Mon Dec 22 12:58:59 2014 +0300
@@ -1400,6 +1400,20 @@ ngx_http_uwsgi_merge_loc_conf(ngx_conf_t
     ngx_hash_init_t               hash;
     ngx_http_core_loc_conf_t     *clcf;
 
+#if (NGX_HTTP_CACHE)
+
+    if (conf->upstream.store > 0) {
+        conf->upstream.cache = NULL;
+    }
+
+    if (conf->upstream.cache != NGX_CONF_UNSET_PTR
+        && conf->upstream.cache != NULL)
+    {
+        conf->upstream.store = 0;
+    }
+
+#endif
+
     if (conf->upstream.store == NGX_CONF_UNSET) {
         ngx_conf_merge_value(conf->upstream.store, prev->upstream.store, 0);
 



More information about the nginx-devel mailing list