Mercurial > hg > nginx-vendor-0-6
comparison src/http/modules/ngx_http_proxy_module.c @ 104:146eff53ab60 NGINX_0_2_6
nginx 0.2.6
*) Change: while using load-balancing the time before the failed
backend retry was decreased from 60 to 10 seconds.
*) Change: the "proxy_pass_unparsed_uri" was canceled, the original URI
now passed, if the URI part is omitted in "proxy_pass" directive.
*) Feature: the "error_page" directive supports redirects and allows
more flexible to change an error code.
*) Change: the charset in the "Content-Type" header line now is ignored
in proxied subrequests.
*) Bugfix: if the URI was changed in the "if" block and request did not
found new configuration, then the ngx_http_rewrite_module rules ran
again.
*) Bugfix: if the "set" directive set the ngx_http_geo_module variable
in some configuration part, the this variable was not available in
other configuration parts and the "using uninitialized variable"
error was occurred; bug appeared in 0.2.2.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Wed, 05 Oct 2005 00:00:00 +0400 |
parents | d6800bbe720e |
children | dad2fe8ecf08 |
comparison
equal
deleted
inserted
replaced
103:acdd83ee07cb | 104:146eff53ab60 |
---|---|
155 { ngx_string("proxy_redirect_errors"), | 155 { ngx_string("proxy_redirect_errors"), |
156 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | 156 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
157 ngx_conf_set_flag_slot, | 157 ngx_conf_set_flag_slot, |
158 NGX_HTTP_LOC_CONF_OFFSET, | 158 NGX_HTTP_LOC_CONF_OFFSET, |
159 offsetof(ngx_http_proxy_loc_conf_t, upstream.redirect_errors), | 159 offsetof(ngx_http_proxy_loc_conf_t, upstream.redirect_errors), |
160 NULL }, | |
161 | |
162 { ngx_string("proxy_pass_unparsed_uri"), | |
163 NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
164 ngx_conf_set_flag_slot, | |
165 NGX_HTTP_LOC_CONF_OFFSET, | |
166 offsetof(ngx_http_proxy_loc_conf_t, upstream.pass_unparsed_uri), | |
167 NULL }, | 160 NULL }, |
168 | 161 |
169 { ngx_string("proxy_set_header"), | 162 { ngx_string("proxy_set_header"), |
170 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, | 163 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, |
171 ngx_conf_set_table_elt_slot, | 164 ngx_conf_set_table_elt_slot, |
338 { ngx_string("proxy_add_via"), NULL, 0, 0, 0 }, | 331 { ngx_string("proxy_add_via"), NULL, 0, 0, 0 }, |
339 #endif | 332 #endif |
340 | 333 |
341 { ngx_null_string, NULL, 0, 0, 0 } | 334 { ngx_null_string, NULL, 0, 0, 0 } |
342 }; | 335 }; |
343 | |
344 | |
345 #if (NGX_PCRE) | |
346 static ngx_str_t ngx_http_proxy_uri = ngx_string("/"); | |
347 #endif | |
348 | 336 |
349 | 337 |
350 static ngx_int_t | 338 static ngx_int_t |
351 ngx_http_proxy_handler(ngx_http_request_t *r) | 339 ngx_http_proxy_handler(ngx_http_request_t *r) |
352 { | 340 { |
430 | 418 |
431 escape = 0; | 419 escape = 0; |
432 | 420 |
433 loc_len = r->valid_location ? u->conf->location->len : 0; | 421 loc_len = r->valid_location ? u->conf->location->len : 0; |
434 | 422 |
435 if (plcf->upstream.pass_unparsed_uri && r->valid_unparsed_uri) { | 423 if (u->conf->uri.len == 0 && r->valid_unparsed_uri) { |
436 len += r->unparsed_uri.len; | 424 len += r->unparsed_uri.len; |
437 | 425 |
438 } else { | 426 } else { |
439 if (r->quoted_uri) { | 427 if (r->quoted_uri) { |
440 escape = 2 * ngx_escape_uri(NULL, r->uri.data + loc_len, | 428 escape = 2 * ngx_escape_uri(NULL, r->uri.data + loc_len, |
512 } else { | 500 } else { |
513 b->last = ngx_cpymem(b->last, r->method_name.data, | 501 b->last = ngx_cpymem(b->last, r->method_name.data, |
514 r->method_name.len + 1); | 502 r->method_name.len + 1); |
515 } | 503 } |
516 | 504 |
517 if (plcf->upstream.pass_unparsed_uri && r->valid_unparsed_uri) { | 505 u->uri.data = b->last; |
506 | |
507 if (u->conf->uri.len == 0 && r->valid_unparsed_uri) { | |
518 b->last = ngx_cpymem(b->last, r->unparsed_uri.data, | 508 b->last = ngx_cpymem(b->last, r->unparsed_uri.data, |
519 r->unparsed_uri.len); | 509 r->unparsed_uri.len); |
520 } else { | 510 } else { |
521 b->last = ngx_cpymem(b->last, u->conf->uri.data, u->conf->uri.len); | 511 if (r->valid_location) { |
512 b->last = ngx_cpymem(b->last, u->conf->uri.data, u->conf->uri.len); | |
513 } | |
522 | 514 |
523 if (escape) { | 515 if (escape) { |
524 ngx_escape_uri(b->last, r->uri.data + loc_len, | 516 ngx_escape_uri(b->last, r->uri.data + loc_len, |
525 r->uri.len - loc_len, NGX_ESCAPE_URI); | 517 r->uri.len - loc_len, NGX_ESCAPE_URI); |
526 b->last += r->uri.len - loc_len + escape; | 518 b->last += r->uri.len - loc_len + escape; |
533 if (r->args.len > 0) { | 525 if (r->args.len > 0) { |
534 *b->last++ = '?'; | 526 *b->last++ = '?'; |
535 b->last = ngx_cpymem(b->last, r->args.data, r->args.len); | 527 b->last = ngx_cpymem(b->last, r->args.data, r->args.len); |
536 } | 528 } |
537 } | 529 } |
530 | |
531 u->uri.len = b->last - u->uri.data; | |
538 | 532 |
539 b->last = ngx_cpymem(b->last, ngx_http_proxy_version, | 533 b->last = ngx_cpymem(b->last, ngx_http_proxy_version, |
540 sizeof(ngx_http_proxy_version) - 1); | 534 sizeof(ngx_http_proxy_version) - 1); |
541 | 535 |
542 | 536 |
1310 | 1304 |
1311 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE; | 1305 conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE; |
1312 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE; | 1306 conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE; |
1313 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE; | 1307 conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE; |
1314 | 1308 |
1315 conf->upstream.pass_unparsed_uri = NGX_CONF_UNSET; | |
1316 conf->upstream.method = NGX_CONF_UNSET_UINT; | 1309 conf->upstream.method = NGX_CONF_UNSET_UINT; |
1317 conf->upstream.pass_request_headers = NGX_CONF_UNSET; | 1310 conf->upstream.pass_request_headers = NGX_CONF_UNSET; |
1318 conf->upstream.pass_request_body = NGX_CONF_UNSET; | 1311 conf->upstream.pass_request_body = NGX_CONF_UNSET; |
1319 | 1312 |
1320 conf->upstream.redirect_errors = NGX_CONF_UNSET; | 1313 conf->upstream.redirect_errors = NGX_CONF_UNSET; |
1465 ngx_conf_merge_path_value(conf->upstream.temp_path, | 1458 ngx_conf_merge_path_value(conf->upstream.temp_path, |
1466 prev->upstream.temp_path, | 1459 prev->upstream.temp_path, |
1467 NGX_HTTP_PROXY_TEMP_PATH, 1, 2, 0, | 1460 NGX_HTTP_PROXY_TEMP_PATH, 1, 2, 0, |
1468 ngx_garbage_collector_temp_handler, cf); | 1461 ngx_garbage_collector_temp_handler, cf); |
1469 | 1462 |
1470 ngx_conf_merge_value(conf->upstream.pass_unparsed_uri, | |
1471 prev->upstream.pass_unparsed_uri, 0); | |
1472 | |
1473 if (conf->upstream.pass_unparsed_uri && conf->upstream.location->len > 1) { | |
1474 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
1475 "\"proxy_pass_unparsed_uri\" can be set for " | |
1476 "location \"/\" or given by regular expression."); | |
1477 return NGX_CONF_ERROR; | |
1478 } | |
1479 | |
1480 if (conf->upstream.method == NGX_CONF_UNSET_UINT) { | 1463 if (conf->upstream.method == NGX_CONF_UNSET_UINT) { |
1481 conf->upstream.method = prev->upstream.method; | 1464 conf->upstream.method = prev->upstream.method; |
1482 } | 1465 } |
1483 | 1466 |
1484 ngx_conf_merge_value(conf->upstream.pass_request_headers, | 1467 ngx_conf_merge_value(conf->upstream.pass_request_headers, |
1757 static char * | 1740 static char * |
1758 ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 1741 ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
1759 { | 1742 { |
1760 ngx_http_proxy_loc_conf_t *plcf = conf; | 1743 ngx_http_proxy_loc_conf_t *plcf = conf; |
1761 | 1744 |
1762 ngx_uint_t i; | |
1763 ngx_str_t *value, *url; | 1745 ngx_str_t *value, *url; |
1764 ngx_inet_upstream_t inet_upstream; | 1746 ngx_inet_upstream_t inet_upstream; |
1765 ngx_http_core_loc_conf_t *clcf; | 1747 ngx_http_core_loc_conf_t *clcf; |
1766 #if (NGX_HAVE_UNIX_DOMAIN) | 1748 #if (NGX_HAVE_UNIX_DOMAIN) |
1767 ngx_unix_domain_upstream_t unix_upstream; | 1749 ngx_unix_domain_upstream_t unix_upstream; |
1768 #endif | 1750 #endif |
1769 | 1751 |
1752 if (plcf->upstream.schema.len) { | |
1753 return "is duplicate"; | |
1754 } | |
1755 | |
1770 value = cf->args->elts; | 1756 value = cf->args->elts; |
1771 | 1757 |
1772 url = &value[1]; | 1758 url = &value[1]; |
1773 | 1759 |
1774 if (ngx_strncasecmp(url->data, "http://", 7) != 0) { | 1760 if (ngx_strncasecmp(url->data, "http://", 7) != 0) { |
1789 | 1775 |
1790 plcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream); | 1776 plcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream); |
1791 if (plcf->peers == NULL) { | 1777 if (plcf->peers == NULL) { |
1792 return NGX_CONF_ERROR; | 1778 return NGX_CONF_ERROR; |
1793 } | 1779 } |
1794 | |
1795 plcf->peers->peer[0].uri_separator = ":"; | |
1796 | 1780 |
1797 plcf->host_header.len = sizeof("localhost") - 1; | 1781 plcf->host_header.len = sizeof("localhost") - 1; |
1798 plcf->host_header.data = (u_char *) "localhost"; | 1782 plcf->host_header.data = (u_char *) "localhost"; |
1799 plcf->upstream.uri = unix_upstream.uri; | 1783 plcf->upstream.uri = unix_upstream.uri; |
1800 | 1784 |
1818 plcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream); | 1802 plcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream); |
1819 if (plcf->peers == NULL) { | 1803 if (plcf->peers == NULL) { |
1820 return NGX_CONF_ERROR; | 1804 return NGX_CONF_ERROR; |
1821 } | 1805 } |
1822 | 1806 |
1823 for (i = 0; i < plcf->peers->number; i++) { | |
1824 plcf->peers->peer[i].uri_separator = ""; | |
1825 } | |
1826 | |
1827 plcf->host_header = inet_upstream.host_header; | 1807 plcf->host_header = inet_upstream.host_header; |
1828 plcf->port_text = inet_upstream.port_text; | 1808 plcf->port_text = inet_upstream.port_text; |
1829 plcf->upstream.uri = inet_upstream.uri; | 1809 plcf->upstream.uri = inet_upstream.uri; |
1830 } | 1810 } |
1831 | 1811 |
1834 | 1814 |
1835 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | 1815 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); |
1836 | 1816 |
1837 clcf->handler = ngx_http_proxy_handler; | 1817 clcf->handler = ngx_http_proxy_handler; |
1838 | 1818 |
1819 plcf->upstream.location = &clcf->name; | |
1820 | |
1839 #if (NGX_PCRE) | 1821 #if (NGX_PCRE) |
1840 plcf->upstream.location = clcf->regex ? &ngx_http_proxy_uri : &clcf->name; | 1822 |
1841 #else | 1823 if (clcf->regex && plcf->upstream.uri.len) { |
1842 plcf->upstream.location = &clcf->name; | 1824 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1825 "\"proxy_pass\" may not have URI part in " | |
1826 "location given by regular expression"); | |
1827 return NGX_CONF_ERROR; | |
1828 } | |
1829 | |
1843 #endif | 1830 #endif |
1844 | 1831 |
1845 plcf->upstream.url = *url; | 1832 plcf->upstream.url = *url; |
1846 | 1833 |
1847 if (clcf->name.data[clcf->name.len - 1] == '/') { | 1834 if (clcf->name.data[clcf->name.len - 1] == '/') { |