Mercurial > hg > nginx
comparison src/http/modules/ngx_http_fastcgi_module.c @ 4277:e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
No functional changes.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 14 Nov 2011 13:24:43 +0000 |
parents | e444e8f6538b |
children | f57229cba7ad |
comparison
equal
deleted
inserted
replaced
4276:a0f18c78db3b | 4277:e4b8255e44c3 |
---|---|
145 | 145 |
146 static ngx_int_t ngx_http_fastcgi_add_variables(ngx_conf_t *cf); | 146 static ngx_int_t ngx_http_fastcgi_add_variables(ngx_conf_t *cf); |
147 static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf); | 147 static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf); |
148 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, | 148 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, |
149 void *parent, void *child); | 149 void *parent, void *child); |
150 static ngx_int_t ngx_http_fastcgi_merge_params(ngx_conf_t *cf, | |
151 ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_loc_conf_t *prev); | |
152 | |
150 static ngx_int_t ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r, | 153 static ngx_int_t ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r, |
151 ngx_http_variable_value_t *v, uintptr_t data); | 154 ngx_http_variable_value_t *v, uintptr_t data); |
152 static ngx_int_t ngx_http_fastcgi_path_info_variable(ngx_http_request_t *r, | 155 static ngx_int_t ngx_http_fastcgi_path_info_variable(ngx_http_request_t *r, |
153 ngx_http_variable_value_t *v, uintptr_t data); | 156 ngx_http_variable_value_t *v, uintptr_t data); |
154 static ngx_http_fastcgi_ctx_t *ngx_http_fastcgi_split(ngx_http_request_t *r, | 157 static ngx_http_fastcgi_ctx_t *ngx_http_fastcgi_split(ngx_http_request_t *r, |
2083 ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | 2086 ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) |
2084 { | 2087 { |
2085 ngx_http_fastcgi_loc_conf_t *prev = parent; | 2088 ngx_http_fastcgi_loc_conf_t *prev = parent; |
2086 ngx_http_fastcgi_loc_conf_t *conf = child; | 2089 ngx_http_fastcgi_loc_conf_t *conf = child; |
2087 | 2090 |
2091 size_t size; | |
2092 ngx_hash_init_t hash; | |
2093 ngx_http_core_loc_conf_t *clcf; | |
2094 | |
2095 if (conf->upstream.store != 0) { | |
2096 ngx_conf_merge_value(conf->upstream.store, | |
2097 prev->upstream.store, 0); | |
2098 | |
2099 if (conf->upstream.store_lengths == NULL) { | |
2100 conf->upstream.store_lengths = prev->upstream.store_lengths; | |
2101 conf->upstream.store_values = prev->upstream.store_values; | |
2102 } | |
2103 } | |
2104 | |
2105 ngx_conf_merge_uint_value(conf->upstream.store_access, | |
2106 prev->upstream.store_access, 0600); | |
2107 | |
2108 ngx_conf_merge_value(conf->upstream.buffering, | |
2109 prev->upstream.buffering, 1); | |
2110 | |
2111 ngx_conf_merge_value(conf->upstream.ignore_client_abort, | |
2112 prev->upstream.ignore_client_abort, 0); | |
2113 | |
2114 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, | |
2115 prev->upstream.connect_timeout, 60000); | |
2116 | |
2117 ngx_conf_merge_msec_value(conf->upstream.send_timeout, | |
2118 prev->upstream.send_timeout, 60000); | |
2119 | |
2120 ngx_conf_merge_msec_value(conf->upstream.read_timeout, | |
2121 prev->upstream.read_timeout, 60000); | |
2122 | |
2123 ngx_conf_merge_size_value(conf->upstream.send_lowat, | |
2124 prev->upstream.send_lowat, 0); | |
2125 | |
2126 ngx_conf_merge_size_value(conf->upstream.buffer_size, | |
2127 prev->upstream.buffer_size, | |
2128 (size_t) ngx_pagesize); | |
2129 | |
2130 | |
2131 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs, | |
2132 8, ngx_pagesize); | |
2133 | |
2134 if (conf->upstream.bufs.num < 2) { | |
2135 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2136 "there must be at least 2 \"fastcgi_buffers\""); | |
2137 return NGX_CONF_ERROR; | |
2138 } | |
2139 | |
2140 | |
2141 size = conf->upstream.buffer_size; | |
2142 if (size < conf->upstream.bufs.size) { | |
2143 size = conf->upstream.bufs.size; | |
2144 } | |
2145 | |
2146 | |
2147 ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf, | |
2148 prev->upstream.busy_buffers_size_conf, | |
2149 NGX_CONF_UNSET_SIZE); | |
2150 | |
2151 if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) { | |
2152 conf->upstream.busy_buffers_size = 2 * size; | |
2153 } else { | |
2154 conf->upstream.busy_buffers_size = | |
2155 conf->upstream.busy_buffers_size_conf; | |
2156 } | |
2157 | |
2158 if (conf->upstream.busy_buffers_size < size) { | |
2159 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2160 "\"fastcgi_busy_buffers_size\" must be equal or bigger than " | |
2161 "maximum of the value of \"fastcgi_buffer_size\" and " | |
2162 "one of the \"fastcgi_buffers\""); | |
2163 | |
2164 return NGX_CONF_ERROR; | |
2165 } | |
2166 | |
2167 if (conf->upstream.busy_buffers_size | |
2168 > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size) | |
2169 { | |
2170 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2171 "\"fastcgi_busy_buffers_size\" must be less than " | |
2172 "the size of all \"fastcgi_buffers\" minus one buffer"); | |
2173 | |
2174 return NGX_CONF_ERROR; | |
2175 } | |
2176 | |
2177 | |
2178 ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf, | |
2179 prev->upstream.temp_file_write_size_conf, | |
2180 NGX_CONF_UNSET_SIZE); | |
2181 | |
2182 if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) { | |
2183 conf->upstream.temp_file_write_size = 2 * size; | |
2184 } else { | |
2185 conf->upstream.temp_file_write_size = | |
2186 conf->upstream.temp_file_write_size_conf; | |
2187 } | |
2188 | |
2189 if (conf->upstream.temp_file_write_size < size) { | |
2190 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2191 "\"fastcgi_temp_file_write_size\" must be equal or bigger than " | |
2192 "maximum of the value of \"fastcgi_buffer_size\" and " | |
2193 "one of the \"fastcgi_buffers\""); | |
2194 | |
2195 return NGX_CONF_ERROR; | |
2196 } | |
2197 | |
2198 | |
2199 ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf, | |
2200 prev->upstream.max_temp_file_size_conf, | |
2201 NGX_CONF_UNSET_SIZE); | |
2202 | |
2203 if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) { | |
2204 conf->upstream.max_temp_file_size = 1024 * 1024 * 1024; | |
2205 } else { | |
2206 conf->upstream.max_temp_file_size = | |
2207 conf->upstream.max_temp_file_size_conf; | |
2208 } | |
2209 | |
2210 if (conf->upstream.max_temp_file_size != 0 | |
2211 && conf->upstream.max_temp_file_size < size) | |
2212 { | |
2213 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2214 "\"fastcgi_max_temp_file_size\" must be equal to zero to disable " | |
2215 "the temporary files usage or must be equal or bigger than " | |
2216 "maximum of the value of \"fastcgi_buffer_size\" and " | |
2217 "one of the \"fastcgi_buffers\""); | |
2218 | |
2219 return NGX_CONF_ERROR; | |
2220 } | |
2221 | |
2222 | |
2223 ngx_conf_merge_bitmask_value(conf->upstream.ignore_headers, | |
2224 prev->upstream.ignore_headers, | |
2225 NGX_CONF_BITMASK_SET); | |
2226 | |
2227 | |
2228 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream, | |
2229 prev->upstream.next_upstream, | |
2230 (NGX_CONF_BITMASK_SET | |
2231 |NGX_HTTP_UPSTREAM_FT_ERROR | |
2232 |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); | |
2233 | |
2234 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { | |
2235 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET | |
2236 |NGX_HTTP_UPSTREAM_FT_OFF; | |
2237 } | |
2238 | |
2239 if (ngx_conf_merge_path_value(cf, &conf->upstream.temp_path, | |
2240 prev->upstream.temp_path, | |
2241 &ngx_http_fastcgi_temp_path) | |
2242 != NGX_OK) | |
2243 { | |
2244 return NGX_CONF_ERROR; | |
2245 } | |
2246 | |
2247 #if (NGX_HTTP_CACHE) | |
2248 | |
2249 ngx_conf_merge_ptr_value(conf->upstream.cache, | |
2250 prev->upstream.cache, NULL); | |
2251 | |
2252 if (conf->upstream.cache && conf->upstream.cache->data == NULL) { | |
2253 ngx_shm_zone_t *shm_zone; | |
2254 | |
2255 shm_zone = conf->upstream.cache; | |
2256 | |
2257 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2258 "\"fastcgi_cache\" zone \"%V\" is unknown", | |
2259 &shm_zone->shm.name); | |
2260 | |
2261 return NGX_CONF_ERROR; | |
2262 } | |
2263 | |
2264 ngx_conf_merge_uint_value(conf->upstream.cache_min_uses, | |
2265 prev->upstream.cache_min_uses, 1); | |
2266 | |
2267 ngx_conf_merge_bitmask_value(conf->upstream.cache_use_stale, | |
2268 prev->upstream.cache_use_stale, | |
2269 (NGX_CONF_BITMASK_SET | |
2270 |NGX_HTTP_UPSTREAM_FT_OFF)); | |
2271 | |
2272 if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_OFF) { | |
2273 conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET | |
2274 |NGX_HTTP_UPSTREAM_FT_OFF; | |
2275 } | |
2276 | |
2277 if (conf->upstream.cache_methods == 0) { | |
2278 conf->upstream.cache_methods = prev->upstream.cache_methods; | |
2279 } | |
2280 | |
2281 conf->upstream.cache_methods |= NGX_HTTP_GET|NGX_HTTP_HEAD; | |
2282 | |
2283 ngx_conf_merge_ptr_value(conf->upstream.cache_bypass, | |
2284 prev->upstream.cache_bypass, NULL); | |
2285 | |
2286 ngx_conf_merge_ptr_value(conf->upstream.no_cache, | |
2287 prev->upstream.no_cache, NULL); | |
2288 | |
2289 if (conf->upstream.no_cache && conf->upstream.cache_bypass == NULL) { | |
2290 ngx_log_error(NGX_LOG_WARN, cf->log, 0, | |
2291 "\"fastcgi_no_cache\" functionality has been changed in 0.8.46, " | |
2292 "now it should be used together with \"fastcgi_cache_bypass\""); | |
2293 } | |
2294 | |
2295 ngx_conf_merge_ptr_value(conf->upstream.cache_valid, | |
2296 prev->upstream.cache_valid, NULL); | |
2297 | |
2298 if (conf->cache_key.value.data == NULL) { | |
2299 conf->cache_key = prev->cache_key; | |
2300 } | |
2301 | |
2302 #endif | |
2303 | |
2304 ngx_conf_merge_value(conf->upstream.pass_request_headers, | |
2305 prev->upstream.pass_request_headers, 1); | |
2306 ngx_conf_merge_value(conf->upstream.pass_request_body, | |
2307 prev->upstream.pass_request_body, 1); | |
2308 | |
2309 ngx_conf_merge_value(conf->upstream.intercept_errors, | |
2310 prev->upstream.intercept_errors, 0); | |
2311 | |
2312 ngx_conf_merge_ptr_value(conf->catch_stderr, prev->catch_stderr, NULL); | |
2313 | |
2314 ngx_conf_merge_value(conf->keep_conn, prev->keep_conn, 0); | |
2315 | |
2316 | |
2317 ngx_conf_merge_str_value(conf->index, prev->index, ""); | |
2318 | |
2319 hash.max_size = 512; | |
2320 hash.bucket_size = ngx_align(64, ngx_cacheline_size); | |
2321 hash.name = "fastcgi_hide_headers_hash"; | |
2322 | |
2323 if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream, | |
2324 &prev->upstream, ngx_http_fastcgi_hide_headers, &hash) | |
2325 != NGX_OK) | |
2326 { | |
2327 return NGX_CONF_ERROR; | |
2328 } | |
2329 | |
2330 if (conf->upstream.upstream == NULL) { | |
2331 conf->upstream.upstream = prev->upstream.upstream; | |
2332 } | |
2333 | |
2334 if (conf->fastcgi_lengths == NULL) { | |
2335 conf->fastcgi_lengths = prev->fastcgi_lengths; | |
2336 conf->fastcgi_values = prev->fastcgi_values; | |
2337 } | |
2338 | |
2339 if (conf->upstream.upstream || conf->fastcgi_lengths) { | |
2340 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | |
2341 if (clcf->handler == NULL && clcf->lmt_excpt) { | |
2342 clcf->handler = ngx_http_fastcgi_handler; | |
2343 } | |
2344 } | |
2345 | |
2346 #if (NGX_PCRE) | |
2347 if (conf->split_regex == NULL) { | |
2348 conf->split_regex = prev->split_regex; | |
2349 conf->split_name = prev->split_name; | |
2350 } | |
2351 #endif | |
2352 | |
2353 if (ngx_http_fastcgi_merge_params(cf, conf, prev) != NGX_OK) { | |
2354 return NGX_CONF_ERROR; | |
2355 } | |
2356 | |
2357 return NGX_CONF_OK; | |
2358 } | |
2359 | |
2360 | |
2361 static ngx_int_t | |
2362 ngx_http_fastcgi_merge_params(ngx_conf_t *cf, | |
2363 ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_loc_conf_t *prev) | |
2364 { | |
2088 u_char *p; | 2365 u_char *p; |
2089 size_t size; | 2366 size_t size; |
2090 uintptr_t *code; | 2367 uintptr_t *code; |
2091 ngx_uint_t i; | 2368 ngx_uint_t i; |
2092 ngx_array_t headers_names; | 2369 ngx_array_t headers_names; |
2093 ngx_keyval_t *src; | 2370 ngx_keyval_t *src; |
2094 ngx_hash_key_t *hk; | 2371 ngx_hash_key_t *hk; |
2095 ngx_hash_init_t hash; | 2372 ngx_hash_init_t hash; |
2096 ngx_http_core_loc_conf_t *clcf; | |
2097 ngx_http_script_compile_t sc; | 2373 ngx_http_script_compile_t sc; |
2098 ngx_http_script_copy_code_t *copy; | 2374 ngx_http_script_copy_code_t *copy; |
2099 | |
2100 if (conf->upstream.store != 0) { | |
2101 ngx_conf_merge_value(conf->upstream.store, | |
2102 prev->upstream.store, 0); | |
2103 | |
2104 if (conf->upstream.store_lengths == NULL) { | |
2105 conf->upstream.store_lengths = prev->upstream.store_lengths; | |
2106 conf->upstream.store_values = prev->upstream.store_values; | |
2107 } | |
2108 } | |
2109 | |
2110 ngx_conf_merge_uint_value(conf->upstream.store_access, | |
2111 prev->upstream.store_access, 0600); | |
2112 | |
2113 ngx_conf_merge_value(conf->upstream.buffering, | |
2114 prev->upstream.buffering, 1); | |
2115 | |
2116 ngx_conf_merge_value(conf->upstream.ignore_client_abort, | |
2117 prev->upstream.ignore_client_abort, 0); | |
2118 | |
2119 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, | |
2120 prev->upstream.connect_timeout, 60000); | |
2121 | |
2122 ngx_conf_merge_msec_value(conf->upstream.send_timeout, | |
2123 prev->upstream.send_timeout, 60000); | |
2124 | |
2125 ngx_conf_merge_msec_value(conf->upstream.read_timeout, | |
2126 prev->upstream.read_timeout, 60000); | |
2127 | |
2128 ngx_conf_merge_size_value(conf->upstream.send_lowat, | |
2129 prev->upstream.send_lowat, 0); | |
2130 | |
2131 ngx_conf_merge_size_value(conf->upstream.buffer_size, | |
2132 prev->upstream.buffer_size, | |
2133 (size_t) ngx_pagesize); | |
2134 | |
2135 | |
2136 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs, | |
2137 8, ngx_pagesize); | |
2138 | |
2139 if (conf->upstream.bufs.num < 2) { | |
2140 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2141 "there must be at least 2 \"fastcgi_buffers\""); | |
2142 return NGX_CONF_ERROR; | |
2143 } | |
2144 | |
2145 | |
2146 size = conf->upstream.buffer_size; | |
2147 if (size < conf->upstream.bufs.size) { | |
2148 size = conf->upstream.bufs.size; | |
2149 } | |
2150 | |
2151 | |
2152 ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf, | |
2153 prev->upstream.busy_buffers_size_conf, | |
2154 NGX_CONF_UNSET_SIZE); | |
2155 | |
2156 if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) { | |
2157 conf->upstream.busy_buffers_size = 2 * size; | |
2158 } else { | |
2159 conf->upstream.busy_buffers_size = | |
2160 conf->upstream.busy_buffers_size_conf; | |
2161 } | |
2162 | |
2163 if (conf->upstream.busy_buffers_size < size) { | |
2164 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2165 "\"fastcgi_busy_buffers_size\" must be equal or bigger than " | |
2166 "maximum of the value of \"fastcgi_buffer_size\" and " | |
2167 "one of the \"fastcgi_buffers\""); | |
2168 | |
2169 return NGX_CONF_ERROR; | |
2170 } | |
2171 | |
2172 if (conf->upstream.busy_buffers_size | |
2173 > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size) | |
2174 { | |
2175 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2176 "\"fastcgi_busy_buffers_size\" must be less than " | |
2177 "the size of all \"fastcgi_buffers\" minus one buffer"); | |
2178 | |
2179 return NGX_CONF_ERROR; | |
2180 } | |
2181 | |
2182 | |
2183 ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf, | |
2184 prev->upstream.temp_file_write_size_conf, | |
2185 NGX_CONF_UNSET_SIZE); | |
2186 | |
2187 if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) { | |
2188 conf->upstream.temp_file_write_size = 2 * size; | |
2189 } else { | |
2190 conf->upstream.temp_file_write_size = | |
2191 conf->upstream.temp_file_write_size_conf; | |
2192 } | |
2193 | |
2194 if (conf->upstream.temp_file_write_size < size) { | |
2195 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2196 "\"fastcgi_temp_file_write_size\" must be equal or bigger than " | |
2197 "maximum of the value of \"fastcgi_buffer_size\" and " | |
2198 "one of the \"fastcgi_buffers\""); | |
2199 | |
2200 return NGX_CONF_ERROR; | |
2201 } | |
2202 | |
2203 | |
2204 ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf, | |
2205 prev->upstream.max_temp_file_size_conf, | |
2206 NGX_CONF_UNSET_SIZE); | |
2207 | |
2208 if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) { | |
2209 conf->upstream.max_temp_file_size = 1024 * 1024 * 1024; | |
2210 } else { | |
2211 conf->upstream.max_temp_file_size = | |
2212 conf->upstream.max_temp_file_size_conf; | |
2213 } | |
2214 | |
2215 if (conf->upstream.max_temp_file_size != 0 | |
2216 && conf->upstream.max_temp_file_size < size) | |
2217 { | |
2218 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2219 "\"fastcgi_max_temp_file_size\" must be equal to zero to disable " | |
2220 "the temporary files usage or must be equal or bigger than " | |
2221 "maximum of the value of \"fastcgi_buffer_size\" and " | |
2222 "one of the \"fastcgi_buffers\""); | |
2223 | |
2224 return NGX_CONF_ERROR; | |
2225 } | |
2226 | |
2227 | |
2228 ngx_conf_merge_bitmask_value(conf->upstream.ignore_headers, | |
2229 prev->upstream.ignore_headers, | |
2230 NGX_CONF_BITMASK_SET); | |
2231 | |
2232 | |
2233 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream, | |
2234 prev->upstream.next_upstream, | |
2235 (NGX_CONF_BITMASK_SET | |
2236 |NGX_HTTP_UPSTREAM_FT_ERROR | |
2237 |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); | |
2238 | |
2239 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { | |
2240 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET | |
2241 |NGX_HTTP_UPSTREAM_FT_OFF; | |
2242 } | |
2243 | |
2244 if (ngx_conf_merge_path_value(cf, &conf->upstream.temp_path, | |
2245 prev->upstream.temp_path, | |
2246 &ngx_http_fastcgi_temp_path) | |
2247 != NGX_OK) | |
2248 { | |
2249 return NGX_CONF_ERROR; | |
2250 } | |
2251 | |
2252 #if (NGX_HTTP_CACHE) | |
2253 | |
2254 ngx_conf_merge_ptr_value(conf->upstream.cache, | |
2255 prev->upstream.cache, NULL); | |
2256 | |
2257 if (conf->upstream.cache && conf->upstream.cache->data == NULL) { | |
2258 ngx_shm_zone_t *shm_zone; | |
2259 | |
2260 shm_zone = conf->upstream.cache; | |
2261 | |
2262 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2263 "\"fastcgi_cache\" zone \"%V\" is unknown", | |
2264 &shm_zone->shm.name); | |
2265 | |
2266 return NGX_CONF_ERROR; | |
2267 } | |
2268 | |
2269 ngx_conf_merge_uint_value(conf->upstream.cache_min_uses, | |
2270 prev->upstream.cache_min_uses, 1); | |
2271 | |
2272 ngx_conf_merge_bitmask_value(conf->upstream.cache_use_stale, | |
2273 prev->upstream.cache_use_stale, | |
2274 (NGX_CONF_BITMASK_SET | |
2275 |NGX_HTTP_UPSTREAM_FT_OFF)); | |
2276 | |
2277 if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_OFF) { | |
2278 conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET | |
2279 |NGX_HTTP_UPSTREAM_FT_OFF; | |
2280 } | |
2281 | |
2282 if (conf->upstream.cache_methods == 0) { | |
2283 conf->upstream.cache_methods = prev->upstream.cache_methods; | |
2284 } | |
2285 | |
2286 conf->upstream.cache_methods |= NGX_HTTP_GET|NGX_HTTP_HEAD; | |
2287 | |
2288 ngx_conf_merge_ptr_value(conf->upstream.cache_bypass, | |
2289 prev->upstream.cache_bypass, NULL); | |
2290 | |
2291 ngx_conf_merge_ptr_value(conf->upstream.no_cache, | |
2292 prev->upstream.no_cache, NULL); | |
2293 | |
2294 if (conf->upstream.no_cache && conf->upstream.cache_bypass == NULL) { | |
2295 ngx_log_error(NGX_LOG_WARN, cf->log, 0, | |
2296 "\"fastcgi_no_cache\" functionality has been changed in 0.8.46, " | |
2297 "now it should be used together with \"fastcgi_cache_bypass\""); | |
2298 } | |
2299 | |
2300 ngx_conf_merge_ptr_value(conf->upstream.cache_valid, | |
2301 prev->upstream.cache_valid, NULL); | |
2302 | |
2303 if (conf->cache_key.value.data == NULL) { | |
2304 conf->cache_key = prev->cache_key; | |
2305 } | |
2306 | |
2307 #endif | |
2308 | |
2309 ngx_conf_merge_value(conf->upstream.pass_request_headers, | |
2310 prev->upstream.pass_request_headers, 1); | |
2311 ngx_conf_merge_value(conf->upstream.pass_request_body, | |
2312 prev->upstream.pass_request_body, 1); | |
2313 | |
2314 ngx_conf_merge_value(conf->upstream.intercept_errors, | |
2315 prev->upstream.intercept_errors, 0); | |
2316 | |
2317 ngx_conf_merge_ptr_value(conf->catch_stderr, prev->catch_stderr, NULL); | |
2318 | |
2319 ngx_conf_merge_value(conf->keep_conn, prev->keep_conn, 0); | |
2320 | |
2321 | |
2322 ngx_conf_merge_str_value(conf->index, prev->index, ""); | |
2323 | |
2324 hash.max_size = 512; | |
2325 hash.bucket_size = ngx_align(64, ngx_cacheline_size); | |
2326 hash.name = "fastcgi_hide_headers_hash"; | |
2327 | |
2328 if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream, | |
2329 &prev->upstream, ngx_http_fastcgi_hide_headers, &hash) | |
2330 != NGX_OK) | |
2331 { | |
2332 return NGX_CONF_ERROR; | |
2333 } | |
2334 | |
2335 if (conf->upstream.upstream == NULL) { | |
2336 conf->upstream.upstream = prev->upstream.upstream; | |
2337 } | |
2338 | |
2339 if (conf->fastcgi_lengths == NULL) { | |
2340 conf->fastcgi_lengths = prev->fastcgi_lengths; | |
2341 conf->fastcgi_values = prev->fastcgi_values; | |
2342 } | |
2343 | |
2344 if (conf->upstream.upstream || conf->fastcgi_lengths) { | |
2345 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | |
2346 if (clcf->handler == NULL && clcf->lmt_excpt) { | |
2347 clcf->handler = ngx_http_fastcgi_handler; | |
2348 } | |
2349 } | |
2350 | |
2351 #if (NGX_PCRE) | |
2352 if (conf->split_regex == NULL) { | |
2353 conf->split_regex = prev->split_regex; | |
2354 conf->split_name = prev->split_name; | |
2355 } | |
2356 #endif | |
2357 | 2375 |
2358 if (conf->params_source == NULL) { | 2376 if (conf->params_source == NULL) { |
2359 conf->flushes = prev->flushes; | 2377 conf->flushes = prev->flushes; |
2360 conf->params_len = prev->params_len; | 2378 conf->params_len = prev->params_len; |
2361 conf->params = prev->params; | 2379 conf->params = prev->params; |
2367 if (conf->params_source == NULL) { | 2385 if (conf->params_source == NULL) { |
2368 | 2386 |
2369 if ((conf->upstream.cache == NULL) | 2387 if ((conf->upstream.cache == NULL) |
2370 == (prev->upstream.cache == NULL)) | 2388 == (prev->upstream.cache == NULL)) |
2371 { | 2389 { |
2372 return NGX_CONF_OK; | 2390 return NGX_OK; |
2373 } | 2391 } |
2374 | 2392 |
2375 /* 6 is a number of ngx_http_fastcgi_cache_headers entries */ | 2393 /* 6 is a number of ngx_http_fastcgi_cache_headers entries */ |
2376 conf->params_source = ngx_array_create(cf->pool, 6, | 2394 conf->params_source = ngx_array_create(cf->pool, 6, |
2377 sizeof(ngx_keyval_t)); | 2395 sizeof(ngx_keyval_t)); |
2378 if (conf->params_source == NULL) { | 2396 if (conf->params_source == NULL) { |
2379 return NGX_CONF_ERROR; | 2397 return NGX_ERROR; |
2380 } | 2398 } |
2381 } | 2399 } |
2382 #else | 2400 #else |
2383 | 2401 |
2384 if (conf->params_source == NULL) { | 2402 if (conf->params_source == NULL) { |
2385 return NGX_CONF_OK; | 2403 return NGX_OK; |
2386 } | 2404 } |
2387 | 2405 |
2388 #endif | 2406 #endif |
2389 } | 2407 } |
2390 | 2408 |
2391 conf->params_len = ngx_array_create(cf->pool, 64, 1); | 2409 conf->params_len = ngx_array_create(cf->pool, 64, 1); |
2392 if (conf->params_len == NULL) { | 2410 if (conf->params_len == NULL) { |
2393 return NGX_CONF_ERROR; | 2411 return NGX_ERROR; |
2394 } | 2412 } |
2395 | 2413 |
2396 conf->params = ngx_array_create(cf->pool, 512, 1); | 2414 conf->params = ngx_array_create(cf->pool, 512, 1); |
2397 if (conf->params == NULL) { | 2415 if (conf->params == NULL) { |
2398 return NGX_CONF_ERROR; | 2416 return NGX_ERROR; |
2399 } | 2417 } |
2400 | 2418 |
2401 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) | 2419 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) |
2402 != NGX_OK) | 2420 != NGX_OK) |
2403 { | 2421 { |
2404 return NGX_CONF_ERROR; | 2422 return NGX_ERROR; |
2405 } | 2423 } |
2406 | 2424 |
2407 src = conf->params_source->elts; | 2425 src = conf->params_source->elts; |
2408 | 2426 |
2409 #if (NGX_HTTP_CACHE) | 2427 #if (NGX_HTTP_CACHE) |
2419 } | 2437 } |
2420 } | 2438 } |
2421 | 2439 |
2422 s = ngx_array_push(conf->params_source); | 2440 s = ngx_array_push(conf->params_source); |
2423 if (s == NULL) { | 2441 if (s == NULL) { |
2424 return NGX_CONF_ERROR; | 2442 return NGX_ERROR; |
2425 } | 2443 } |
2426 | 2444 |
2427 *s = *h; | 2445 *s = *h; |
2428 | 2446 |
2429 src = conf->params_source->elts; | 2447 src = conf->params_source->elts; |
2441 if (src[i].key.len > sizeof("HTTP_") - 1 | 2459 if (src[i].key.len > sizeof("HTTP_") - 1 |
2442 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0) | 2460 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0) |
2443 { | 2461 { |
2444 hk = ngx_array_push(&headers_names); | 2462 hk = ngx_array_push(&headers_names); |
2445 if (hk == NULL) { | 2463 if (hk == NULL) { |
2446 return NGX_CONF_ERROR; | 2464 return NGX_ERROR; |
2447 } | 2465 } |
2448 | 2466 |
2449 hk->key.len = src[i].key.len - 5; | 2467 hk->key.len = src[i].key.len - 5; |
2450 hk->key.data = src[i].key.data + 5; | 2468 hk->key.data = src[i].key.data + 5; |
2451 hk->key_hash = ngx_hash_key_lc(hk->key.data, hk->key.len); | 2469 hk->key_hash = ngx_hash_key_lc(hk->key.data, hk->key.len); |
2457 } | 2475 } |
2458 | 2476 |
2459 copy = ngx_array_push_n(conf->params_len, | 2477 copy = ngx_array_push_n(conf->params_len, |
2460 sizeof(ngx_http_script_copy_code_t)); | 2478 sizeof(ngx_http_script_copy_code_t)); |
2461 if (copy == NULL) { | 2479 if (copy == NULL) { |
2462 return NGX_CONF_ERROR; | 2480 return NGX_ERROR; |
2463 } | 2481 } |
2464 | 2482 |
2465 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; | 2483 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; |
2466 copy->len = src[i].key.len; | 2484 copy->len = src[i].key.len; |
2467 | 2485 |
2468 | 2486 |
2469 size = (sizeof(ngx_http_script_copy_code_t) | 2487 size = (sizeof(ngx_http_script_copy_code_t) |
2470 + src[i].key.len + sizeof(uintptr_t) - 1) | 2488 + src[i].key.len + sizeof(uintptr_t) - 1) |
2471 & ~(sizeof(uintptr_t) - 1); | 2489 & ~(sizeof(uintptr_t) - 1); |
2472 | 2490 |
2473 copy = ngx_array_push_n(conf->params, size); | 2491 copy = ngx_array_push_n(conf->params, size); |
2474 if (copy == NULL) { | 2492 if (copy == NULL) { |
2475 return NGX_CONF_ERROR; | 2493 return NGX_ERROR; |
2476 } | 2494 } |
2477 | 2495 |
2478 copy->code = ngx_http_script_copy_code; | 2496 copy->code = ngx_http_script_copy_code; |
2479 copy->len = src[i].key.len; | 2497 copy->len = src[i].key.len; |
2480 | 2498 |
2489 sc.flushes = &conf->flushes; | 2507 sc.flushes = &conf->flushes; |
2490 sc.lengths = &conf->params_len; | 2508 sc.lengths = &conf->params_len; |
2491 sc.values = &conf->params; | 2509 sc.values = &conf->params; |
2492 | 2510 |
2493 if (ngx_http_script_compile(&sc) != NGX_OK) { | 2511 if (ngx_http_script_compile(&sc) != NGX_OK) { |
2494 return NGX_CONF_ERROR; | 2512 return NGX_ERROR; |
2495 } | 2513 } |
2496 | 2514 |
2497 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | 2515 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); |
2498 if (code == NULL) { | 2516 if (code == NULL) { |
2499 return NGX_CONF_ERROR; | 2517 return NGX_ERROR; |
2500 } | 2518 } |
2501 | 2519 |
2502 *code = (uintptr_t) NULL; | 2520 *code = (uintptr_t) NULL; |
2503 | 2521 |
2504 | 2522 |
2505 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); | 2523 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); |
2506 if (code == NULL) { | 2524 if (code == NULL) { |
2507 return NGX_CONF_ERROR; | 2525 return NGX_ERROR; |
2508 } | 2526 } |
2509 | 2527 |
2510 *code = (uintptr_t) NULL; | 2528 *code = (uintptr_t) NULL; |
2511 } | 2529 } |
2512 | 2530 |
2513 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | 2531 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); |
2514 if (code == NULL) { | 2532 if (code == NULL) { |
2515 return NGX_CONF_ERROR; | 2533 return NGX_ERROR; |
2516 } | 2534 } |
2517 | 2535 |
2518 *code = (uintptr_t) NULL; | 2536 *code = (uintptr_t) NULL; |
2519 | |
2520 | 2537 |
2521 conf->header_params = headers_names.nelts; | 2538 conf->header_params = headers_names.nelts; |
2522 | 2539 |
2523 hash.hash = &conf->headers_hash; | 2540 hash.hash = &conf->headers_hash; |
2524 hash.key = ngx_hash_key_lc; | 2541 hash.key = ngx_hash_key_lc; |
2526 hash.bucket_size = 64; | 2543 hash.bucket_size = 64; |
2527 hash.name = "fastcgi_params_hash"; | 2544 hash.name = "fastcgi_params_hash"; |
2528 hash.pool = cf->pool; | 2545 hash.pool = cf->pool; |
2529 hash.temp_pool = NULL; | 2546 hash.temp_pool = NULL; |
2530 | 2547 |
2531 if (ngx_hash_init(&hash, headers_names.elts, headers_names.nelts) != NGX_OK) | 2548 return ngx_hash_init(&hash, headers_names.elts, headers_names.nelts); |
2532 { | |
2533 return NGX_CONF_ERROR; | |
2534 } | |
2535 | |
2536 return NGX_CONF_OK; | |
2537 } | 2549 } |
2538 | 2550 |
2539 | 2551 |
2540 static ngx_int_t | 2552 static ngx_int_t |
2541 ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r, | 2553 ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r, |