comparison src/http/modules/ngx_http_fastcgi_module.c @ 466:9eda3153223b NGINX_0_7_45

nginx 0.7.45 *) Change: now the "proxy_cache" and the "proxy_cache_valid" can be set on different levels. *) Change: the "clean_time" parameter of the "proxy_cache_path" directive is canceled. *) Feature: the "max_size" parameter of the "proxy_cache_path" directive. *) Feature: the ngx_http_fastcgi_module preliminary cache support. *) Feature: now on shared memory allocation errors directive and zone names are logged. *) Bugfix: the directive "add_header last-modified ''" did not delete a "Last-Modified" response header line; the bug had appeared in 0.7.44. *) Bugfix: a relative path in the "auth_basic_user_file" directive given without variables did not work; the bug had appeared in 0.7.44. Thanks to Jerome Loyet. *) Bugfix: in an "alias" directive given using variables without references to captures of regular expressions; the bug had appeared in 0.7.42.
author Igor Sysoev <http://sysoev.ru>
date Mon, 30 Mar 2009 00:00:00 +0400
parents c8cfb6c462ef
children 09f0ef15d544
comparison
equal deleted inserted replaced
465:29602be46850 466:9eda3153223b
20 ngx_array_t *params_source; 20 ngx_array_t *params_source;
21 ngx_array_t *catch_stderr; 21 ngx_array_t *catch_stderr;
22 22
23 ngx_array_t *fastcgi_lengths; 23 ngx_array_t *fastcgi_lengths;
24 ngx_array_t *fastcgi_values; 24 ngx_array_t *fastcgi_values;
25
26 #if (NGX_HTTP_CACHE)
27 ngx_http_complex_value_t cache_key;
28 #endif
25 29
26 #if (NGX_PCRE) 30 #if (NGX_PCRE)
27 ngx_regex_t *split_regex; 31 ngx_regex_t *split_regex;
28 ngx_str_t split_name; 32 ngx_str_t split_name;
29 #endif 33 #endif
114 } ngx_http_fastcgi_request_start_t; 118 } ngx_http_fastcgi_request_start_t;
115 119
116 120
117 static ngx_int_t ngx_http_fastcgi_eval(ngx_http_request_t *r, 121 static ngx_int_t ngx_http_fastcgi_eval(ngx_http_request_t *r,
118 ngx_http_fastcgi_loc_conf_t *flcf); 122 ngx_http_fastcgi_loc_conf_t *flcf);
123 #if (NGX_HTTP_CACHE)
124 static ngx_int_t ngx_http_fastcgi_create_key(ngx_http_request_t *r);
125 #endif
119 static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r); 126 static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r);
120 static ngx_int_t ngx_http_fastcgi_reinit_request(ngx_http_request_t *r); 127 static ngx_int_t ngx_http_fastcgi_reinit_request(ngx_http_request_t *r);
121 static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r); 128 static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r);
122 static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, 129 static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p,
123 ngx_buf_t *buf); 130 ngx_buf_t *buf);
142 void *conf); 149 void *conf);
143 static char *ngx_http_fastcgi_split_path_info(ngx_conf_t *cf, 150 static char *ngx_http_fastcgi_split_path_info(ngx_conf_t *cf,
144 ngx_command_t *cmd, void *conf); 151 ngx_command_t *cmd, void *conf);
145 static char *ngx_http_fastcgi_store(ngx_conf_t *cf, ngx_command_t *cmd, 152 static char *ngx_http_fastcgi_store(ngx_conf_t *cf, ngx_command_t *cmd,
146 void *conf); 153 void *conf);
154 #if (NGX_HTTP_CACHE)
155 static char *ngx_http_fastcgi_cache(ngx_conf_t *cf, ngx_command_t *cmd,
156 void *conf);
157 static char *ngx_http_fastcgi_cache_key(ngx_conf_t *cf, ngx_command_t *cmd,
158 void *conf);
159 #endif
160
147 static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, 161 static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post,
148 void *data); 162 void *data);
149 163
150 static char *ngx_http_fastcgi_upstream_max_fails_unsupported(ngx_conf_t *cf, 164 static char *ngx_http_fastcgi_upstream_max_fails_unsupported(ngx_conf_t *cf,
151 ngx_command_t *cmd, void *conf); 165 ngx_command_t *cmd, void *conf);
167 { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF }, 181 { ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF },
168 { ngx_null_string, 0 } 182 { ngx_null_string, 0 }
169 }; 183 };
170 184
171 185
186 ngx_module_t ngx_http_fastcgi_module;
187
188
172 static ngx_command_t ngx_http_fastcgi_commands[] = { 189 static ngx_command_t ngx_http_fastcgi_commands[] = {
173 190
174 { ngx_string("fastcgi_pass"), 191 { ngx_string("fastcgi_pass"),
175 NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1, 192 NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
176 ngx_http_fastcgi_pass, 193 ngx_http_fastcgi_pass,
280 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 297 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
281 ngx_conf_set_size_slot, 298 ngx_conf_set_size_slot,
282 NGX_HTTP_LOC_CONF_OFFSET, 299 NGX_HTTP_LOC_CONF_OFFSET,
283 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.busy_buffers_size_conf), 300 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.busy_buffers_size_conf),
284 NULL }, 301 NULL },
302
303 #if (NGX_HTTP_CACHE)
304
305 { ngx_string("fastcgi_cache"),
306 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
307 ngx_http_fastcgi_cache,
308 NGX_HTTP_LOC_CONF_OFFSET,
309 0,
310 NULL },
311
312 { ngx_string("fastcgi_cache_key"),
313 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
314 ngx_http_fastcgi_cache_key,
315 NGX_HTTP_LOC_CONF_OFFSET,
316 0,
317 NULL },
318
319 { ngx_string("fastcgi_cache_path"),
320 NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE,
321 ngx_http_file_cache_set_slot,
322 0,
323 0,
324 &ngx_http_fastcgi_module },
325
326 { ngx_string("fastcgi_cache_valid"),
327 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
328 ngx_http_file_cache_valid_set_slot,
329 NGX_HTTP_LOC_CONF_OFFSET,
330 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_valid),
331 NULL },
332
333 { ngx_string("proxy_cache_min_uses"),
334 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
335 ngx_conf_set_num_slot,
336 NGX_HTTP_LOC_CONF_OFFSET,
337 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_min_uses),
338 NULL },
339
340 { ngx_string("fastcgi_cache_use_stale"),
341 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
342 ngx_conf_set_bitmask_slot,
343 NGX_HTTP_LOC_CONF_OFFSET,
344 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.cache_use_stale),
345 &ngx_http_fastcgi_next_upstream_masks },
346
347 #endif
285 348
286 { ngx_string("fastcgi_temp_path"), 349 { ngx_string("fastcgi_temp_path"),
287 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234, 350 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
288 ngx_conf_set_path_slot, 351 ngx_conf_set_path_slot,
289 NGX_HTTP_LOC_CONF_OFFSET, 352 NGX_HTTP_LOC_CONF_OFFSET,
489 552
490 u->output.tag = (ngx_buf_tag_t) &ngx_http_fastcgi_module; 553 u->output.tag = (ngx_buf_tag_t) &ngx_http_fastcgi_module;
491 554
492 u->conf = &flcf->upstream; 555 u->conf = &flcf->upstream;
493 556
557 #if (NGX_HTTP_CACHE)
558 u->create_key = ngx_http_fastcgi_create_key;
559 #endif
494 u->create_request = ngx_http_fastcgi_create_request; 560 u->create_request = ngx_http_fastcgi_create_request;
495 u->reinit_request = ngx_http_fastcgi_reinit_request; 561 u->reinit_request = ngx_http_fastcgi_reinit_request;
496 u->process_header = ngx_http_fastcgi_process_header; 562 u->process_header = ngx_http_fastcgi_process_header;
497 u->abort_request = ngx_http_fastcgi_abort_request; 563 u->abort_request = ngx_http_fastcgi_abort_request;
498 u->finalize_request = ngx_http_fastcgi_finalize_request; 564 u->finalize_request = ngx_http_fastcgi_finalize_request;
542 return NGX_ERROR; 608 return NGX_ERROR;
543 } 609 }
544 610
545 if (u.no_port) { 611 if (u.no_port) {
546 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 612 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
547 "no port in upstream \"%V\"", &u.url); 613 "no port in upstream \"%V\"", &u.url);
548 return NGX_ERROR; 614 return NGX_ERROR;
549 } 615 }
550 616
551 r->upstream->resolved = ngx_pcalloc(r->pool, 617 r->upstream->resolved = ngx_pcalloc(r->pool,
552 sizeof(ngx_http_upstream_resolved_t)); 618 sizeof(ngx_http_upstream_resolved_t));
565 r->upstream->resolved->port = u.port; 631 r->upstream->resolved->port = u.port;
566 } 632 }
567 633
568 return NGX_OK; 634 return NGX_OK;
569 } 635 }
636
637
638 #if (NGX_HTTP_CACHE)
639
640 static ngx_int_t
641 ngx_http_fastcgi_create_key(ngx_http_request_t *r)
642 {
643 ngx_str_t *key;
644 ngx_http_fastcgi_loc_conf_t *flcf;
645
646 key = ngx_array_push(&r->cache->keys);
647 if (key == NULL) {
648 return NGX_ERROR;
649 }
650
651 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
652
653 if (ngx_http_complex_value(r, &flcf->cache_key, key) != NGX_OK) {
654 return NGX_ERROR;
655 }
656
657 return NGX_OK;
658 }
659
660 #endif
570 661
571 662
572 static ngx_int_t 663 static ngx_int_t
573 ngx_http_fastcgi_create_request(ngx_http_request_t *r) 664 ngx_http_fastcgi_create_request(ngx_http_request_t *r)
574 { 665 {
1274 u->headers_in.status_n = 200; 1365 u->headers_in.status_n = 200;
1275 u->headers_in.status_line.len = sizeof("200 OK") - 1; 1366 u->headers_in.status_line.len = sizeof("200 OK") - 1;
1276 u->headers_in.status_line.data = (u_char *) "200 OK"; 1367 u->headers_in.status_line.data = (u_char *) "200 OK";
1277 } 1368 }
1278 1369
1279 u->state->status = u->headers_in.status_n; 1370 if (u->state) {
1280 #if 0 1371 u->state->status = u->headers_in.status_n;
1281 if (u->cacheable) {
1282 u->cacheable = ngx_http_upstream_is_cacheable(r);
1283 } 1372 }
1284 #endif
1285 1373
1286 break; 1374 break;
1287 } 1375 }
1288 1376
1289 /* there was error while a header line parsing */ 1377 /* there was error while a header line parsing */
1728 /* 1816 /*
1729 * set by ngx_pcalloc(): 1817 * set by ngx_pcalloc():
1730 * 1818 *
1731 * conf->upstream.bufs.num = 0; 1819 * conf->upstream.bufs.num = 0;
1732 * conf->upstream.next_upstream = 0; 1820 * conf->upstream.next_upstream = 0;
1821 * conf->upstream.use_stale_cache = 0;
1733 * conf->upstream.temp_path = NULL; 1822 * conf->upstream.temp_path = NULL;
1734 * conf->upstream.hide_headers_hash = { NULL, 0 }; 1823 * conf->upstream.hide_headers_hash = { NULL, 0 };
1735 * conf->upstream.uri = { 0, NULL }; 1824 * conf->upstream.uri = { 0, NULL };
1736 * conf->upstream.location = NULL; 1825 * conf->upstream.location = NULL;
1737 * conf->upstream.store_lengths = NULL; 1826 * conf->upstream.store_lengths = NULL;
1758 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE; 1847 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE;
1759 1848
1760 conf->upstream.pass_request_headers = NGX_CONF_UNSET; 1849 conf->upstream.pass_request_headers = NGX_CONF_UNSET;
1761 conf->upstream.pass_request_body = NGX_CONF_UNSET; 1850 conf->upstream.pass_request_body = NGX_CONF_UNSET;
1762 1851
1852 #if (NGX_HTTP_CACHE)
1853 conf->upstream.cache = NGX_CONF_UNSET_PTR;
1854 conf->upstream.cache_min_uses = NGX_CONF_UNSET_UINT;
1855 conf->upstream.cache_valid = NGX_CONF_UNSET_PTR;
1856 #endif
1857
1763 conf->upstream.hide_headers = NGX_CONF_UNSET_PTR; 1858 conf->upstream.hide_headers = NGX_CONF_UNSET_PTR;
1764 conf->upstream.pass_headers = NGX_CONF_UNSET_PTR; 1859 conf->upstream.pass_headers = NGX_CONF_UNSET_PTR;
1765 1860
1766 conf->upstream.intercept_errors = NGX_CONF_UNSET; 1861 conf->upstream.intercept_errors = NGX_CONF_UNSET;
1767 1862
1934 != NGX_OK) 2029 != NGX_OK)
1935 { 2030 {
1936 return NGX_CONF_ERROR; 2031 return NGX_CONF_ERROR;
1937 } 2032 }
1938 2033
2034 #if (NGX_HTTP_CACHE)
2035
2036 ngx_conf_merge_ptr_value(conf->upstream.cache,
2037 prev->upstream.cache, NULL);
2038
2039 if (conf->upstream.cache && conf->upstream.cache->data == NULL) {
2040 ngx_shm_zone_t *shm_zone;
2041
2042 shm_zone = conf->upstream.cache;
2043
2044 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2045 "\"fastcgi_cache\" zone \"%V\" is unknown",
2046 &shm_zone->name);
2047
2048 return NGX_CONF_ERROR;
2049 }
2050
2051 ngx_conf_merge_uint_value(conf->upstream.cache_min_uses,
2052 prev->upstream.cache_min_uses, 1);
2053
2054 ngx_conf_merge_bitmask_value(conf->upstream.cache_use_stale,
2055 prev->upstream.cache_use_stale,
2056 (NGX_CONF_BITMASK_SET
2057 |NGX_HTTP_UPSTREAM_FT_OFF));
2058
2059 if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_OFF) {
2060 conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET
2061 |NGX_HTTP_UPSTREAM_FT_OFF;
2062 }
2063
2064 ngx_conf_merge_ptr_value(conf->upstream.cache_valid,
2065 prev->upstream.cache_valid, NULL);
2066
2067 #endif
2068
1939 ngx_conf_merge_value(conf->upstream.pass_request_headers, 2069 ngx_conf_merge_value(conf->upstream.pass_request_headers,
1940 prev->upstream.pass_request_headers, 1); 2070 prev->upstream.pass_request_headers, 1);
1941 ngx_conf_merge_value(conf->upstream.pass_request_body, 2071 ngx_conf_merge_value(conf->upstream.pass_request_body,
1942 prev->upstream.pass_request_body, 1); 2072 prev->upstream.pass_request_body, 1);
1943 2073
2407 2537
2408 return NGX_CONF_OK; 2538 return NGX_CONF_OK;
2409 } 2539 }
2410 2540
2411 2541
2542 #if (NGX_HTTP_CACHE)
2543
2544 static char *
2545 ngx_http_fastcgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2546 {
2547 ngx_http_fastcgi_loc_conf_t *flcf = conf;
2548
2549 ngx_str_t *value;
2550
2551 value = cf->args->elts;
2552
2553 if (flcf->upstream.cache != NGX_CONF_UNSET_PTR) {
2554 return "is duplicate";
2555 }
2556
2557 if (ngx_strcmp(value[1].data, "off") == 0) {
2558 flcf->upstream.cache = NULL;
2559 return NGX_CONF_OK;
2560 }
2561
2562 flcf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0,
2563 &ngx_http_fastcgi_module);
2564 if (flcf->upstream.cache == NULL) {
2565 return NGX_CONF_ERROR;
2566 }
2567
2568 return NGX_CONF_OK;
2569 }
2570
2571
2572 static char *
2573 ngx_http_fastcgi_cache_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2574 {
2575 ngx_http_fastcgi_loc_conf_t *flcf = conf;
2576
2577 ngx_str_t *value;
2578 ngx_http_compile_complex_value_t ccv;
2579
2580 value = cf->args->elts;
2581
2582 if (flcf->cache_key.value.len) {
2583 return "is duplicate";
2584 }
2585
2586 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
2587
2588 ccv.cf = cf;
2589 ccv.value = &value[1];
2590 ccv.complex_value = &flcf->cache_key;
2591
2592 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
2593 return NGX_CONF_ERROR;
2594 }
2595
2596 return NGX_CONF_OK;
2597 }
2598
2599 #endif
2600
2601
2412 static char * 2602 static char *
2413 ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, void *data) 2603 ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, void *data)
2414 { 2604 {
2415 #if (NGX_FREEBSD) 2605 #if (NGX_FREEBSD)
2416 ssize_t *np = data; 2606 ssize_t *np = data;