From cdd650c95faeeed01ad88c199a5f51bd6e03c49e Mon Sep 17 00:00:00 2001
From: "Hongli Lai (Phusion)" <hongli@phusion.nl>
Date: Fri, 2 Jan 2015 14:57:10 +0100
Subject: [PATCH] Fix compatibility with Nginx 1.7.9
Closes GH-1335.
---
CHANGELOG | 1 +
ext/nginx/Configuration.c | 85 ++++++++++++++++++++++++++++++++++++++---------
2 files changed, 70 insertions(+), 16 deletions(-)
diff --git a/ext/nginx/Configuration.c b/ext/nginx/Configuration.c
index 94b19dc..6d594d9 100644
--- a/ext/nginx/Configuration.c
+++ b/ext/nginx/Configuration.c
@@ -268,7 +268,11 @@ passenger_create_loc_conf(ngx_conf_t *cf)
conf->upstream_config.pass_request_body = NGX_CONF_UNSET;
#if (NGX_HTTP_CACHE)
- conf->upstream_config.cache = NGX_CONF_UNSET_PTR;
+ #if NGINX_VERSION_NUM >= 1007009
+ conf->upstream_config.cache = NGX_CONF_UNSET_PTR;
+ #else
+ conf->upstream_config.cache = NGX_CONF_UNSET;
+ #endif
conf->upstream_config.cache_min_uses = NGX_CONF_UNSET_UINT;
conf->upstream_config.cache_bypass = NGX_CONF_UNSET_PTR;
conf->upstream_config.no_cache = NGX_CONF_UNSET_PTR;
@@ -277,6 +281,9 @@ passenger_create_loc_conf(ngx_conf_t *cf)
conf->upstream_config.cache_lock = NGX_CONF_UNSET;
conf->upstream_config.cache_lock_timeout = NGX_CONF_UNSET_MSEC;
#endif
+ #if NGINX_VERSION_NUM >= 1007008
+ conf->upstream_config.cache_lock_age = NGX_CONF_UNSET_MSEC;
+ #endif
#endif
conf->upstream_config.intercept_errors = NGX_CONF_UNSET;
@@ -382,15 +389,34 @@ passenger_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
/******************************/
/******************************/
- if (conf->upstream_config.store != 0) {
- ngx_conf_merge_value(conf->upstream_config.store,
- prev->upstream_config.store, 0);
+ #if (NGX_HTTP_CACHE) && NGINX_VERSION_NUM >= 1007009
+ if (conf->upstream_config.store > 0) {
+ conf->upstream_config.cache = 0;
+ }
+ if (conf->upstream_config.cache > 0) {
+ conf->upstream_config.store = 0;
+ }
+ #endif
+
+ #if NGINX_VERSION_NUM >= 1007009
+ if (conf->upstream_config.store == NGX_CONF_UNSET) {
+ ngx_conf_merge_value(conf->upstream_config.store,
+ prev->upstream_config.store, 0);
- if (conf->upstream_config.store_lengths == NULL) {
conf->upstream_config.store_lengths = prev->upstream_config.store_lengths;
conf->upstream_config.store_values = prev->upstream_config.store_values;
}
- }
+ #else
+ if (conf->upstream_config.store != 0) {
+ ngx_conf_merge_value(conf->upstream_config.store,
+ prev->upstream_config.store, 0);
+
+ if (conf->upstream_config.store_lengths == NULL) {
+ conf->upstream_config.store_lengths = prev->upstream_config.store_lengths;
+ conf->upstream_config.store_values = prev->upstream_config.store_values;
+ }
+ }
+ #endif
ngx_conf_merge_uint_value(conf->upstream_config.store_access,
prev->upstream_config.store_access, 0600);
@@ -554,20 +580,42 @@ passenger_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
#if (NGX_HTTP_CACHE)
- ngx_conf_merge_ptr_value(conf->upstream_config.cache,
- prev->upstream_config.cache, NULL);
+ #if NGINX_VERSION_NUM >= 1007009
+ if (conf->upstream_config.cache == NGX_CONF_UNSET) {
+ ngx_conf_merge_value(conf->upstream_config.cache,
+ prev->upstream_config.cache, 0);
- if (conf->upstream_config.cache && conf->upstream_config.cache->data == NULL) {
- ngx_shm_zone_t *shm_zone;
+ conf->upstream_config.cache_zone = prev->upstream_config.cache_zone;
+ conf->upstream_config.cache_value = prev->upstream_config.cache_value;
+ }
- shm_zone = conf->upstream_config.cache;
+ if (conf->upstream_config.cache_zone && conf->upstream_config.cache_zone->data == NULL) {
+ ngx_shm_zone_t *shm_zone;
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "\"scgi_cache\" zone \"%V\" is unknown",
- &shm_zone->shm.name);
+ shm_zone = conf->upstream_config.cache_zone;
- return NGX_CONF_ERROR;
- }
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "\"scgi_cache\" zone \"%V\" is unknown",
+ &shm_zone->shm.name);
+
+ return NGX_CONF_ERROR;
+ }
+ #else
+ ngx_conf_merge_ptr_value(conf->upstream_config.cache,
+ prev->upstream_config.cache, NULL);
+
+ if (conf->upstream_config.cache && conf->upstream_config.cache->data == NULL) {
+ ngx_shm_zone_t *shm_zone;
+
+ shm_zone = conf->upstream_config.cache;
+
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "\"scgi_cache\" zone \"%V\" is unknown",
+ &shm_zone->shm.name);
+
+ return NGX_CONF_ERROR;
+ }
+ #endif
ngx_conf_merge_uint_value(conf->upstream_config.cache_min_uses,
prev->upstream_config.cache_min_uses, 1);
@@ -613,6 +661,11 @@ passenger_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
prev->upstream_config.cache_lock_timeout, 5000);
#endif
+ #if NGINX_VERSION_NUM >= 1007008
+ ngx_conf_merge_msec_value(conf->upstream_config.cache_lock_age,
+ prev->upstream_config.cache_lock_age, 5000);
+ #endif
+
#endif
ngx_conf_merge_value(conf->upstream_config.pass_request_headers,
diff --git a/ext/nginx/Configuration.c b/ext/nginx/Configuration.c
index b357dcb..762bf44 100644
--- a/ext/nginx/Configuration.c
+++ b/ext/nginx/Configuration.c
@@ -310,9 +310,9 @@ passenger_create_loc_conf(ngx_conf_t *cf)
#if (NGX_HTTP_CACHE)
#if NGINX_VERSION_NUM >= 1007009
- conf->upstream_config.cache = NGX_CONF_UNSET_PTR;
- #else
conf->upstream_config.cache = NGX_CONF_UNSET;
+ #else
+ conf->upstream_config.cache = NGX_CONF_UNSET_PTR;
#endif
conf->upstream_config.cache_min_uses = NGX_CONF_UNSET_UINT;
conf->upstream_config.cache_bypass = NGX_CONF_UNSET_PTR;