comparison src/http/modules/ngx_http_proxy_module.c @ 200:d2ae1c9f1fd3 NGINX_0_3_47

nginx 0.3.47 *) Feature: the "upstream" directive. *) Change: now the "\" escape symbol in the "\"" and "\'" pairs in the SSI command is always removed.
author Igor Sysoev <http://sysoev.ru>
date Tue, 23 May 2006 00:00:00 +0400
parents e6da4931e0e0
children ca5f86d94316
comparison
equal deleted inserted replaced
199:869664706c09 200:d2ae1c9f1fd3
14 14
15 typedef ngx_int_t (*ngx_http_proxy_redirect_pt)(ngx_http_request_t *r, 15 typedef ngx_int_t (*ngx_http_proxy_redirect_pt)(ngx_http_request_t *r,
16 ngx_table_elt_t *h, size_t prefix, ngx_http_proxy_redirect_t *pr); 16 ngx_table_elt_t *h, size_t prefix, ngx_http_proxy_redirect_t *pr);
17 17
18 struct ngx_http_proxy_redirect_s { 18 struct ngx_http_proxy_redirect_s {
19 ngx_http_proxy_redirect_pt handler; 19 ngx_http_proxy_redirect_pt handler;
20 ngx_str_t redirect; 20 ngx_str_t redirect;
21 21
22 union { 22 union {
23 ngx_str_t text; 23 ngx_str_t text;
24 24
25 struct { 25 struct {
26 void *lengths; 26 void *lengths;
27 void *values; 27 void *values;
28 } vars; 28 } vars;
29 29
30 void *regex; 30 void *regex;
31 } replacement; 31 } replacement;
32 }; 32 };
33 33
34 34
35 typedef struct { 35 typedef struct {
36 ngx_http_upstream_conf_t upstream; 36 ngx_http_upstream_conf_t upstream;
37 37
38 ngx_peers_t *peers; 38 ngx_http_upstream_srv_conf_t *upstream_peers;
39 39
40 ngx_array_t *flushes; 40 ngx_array_t *flushes;
41 ngx_array_t *body_set_len; 41 ngx_array_t *body_set_len;
42 ngx_array_t *body_set; 42 ngx_array_t *body_set;
43 ngx_array_t *headers_set_len; 43 ngx_array_t *headers_set_len;
44 ngx_array_t *headers_set; 44 ngx_array_t *headers_set;
45 ngx_hash_t headers_set_hash; 45 ngx_hash_t headers_set_hash;
46 46
47 ngx_array_t *headers_source; 47 ngx_array_t *headers_source;
48 ngx_array_t *headers_names; 48 ngx_array_t *headers_names;
49 49
50 ngx_array_t *redirects; 50 ngx_array_t *redirects;
51 51
52 ngx_str_t body_source; 52 ngx_str_t body_source;
53 53
54 ngx_str_t method; 54 ngx_str_t method;
55 ngx_str_t host_header; 55 ngx_str_t host_header;
56 ngx_str_t port_text; 56 ngx_str_t port_text;
57 57
58 ngx_flag_t redirect; 58 ngx_flag_t redirect;
59 } ngx_http_proxy_loc_conf_t; 59 } ngx_http_proxy_loc_conf_t;
60 60
61 61
62 typedef struct { 62 typedef struct {
63 ngx_uint_t status; 63 ngx_uint_t status;
64 ngx_uint_t status_count; 64 ngx_uint_t status_count;
65 u_char *status_start; 65 u_char *status_start;
66 u_char *status_end; 66 u_char *status_end;
67 67
68 size_t internal_body_length; 68 size_t internal_body_length;
69 } ngx_http_proxy_ctx_t; 69 } ngx_http_proxy_ctx_t;
70 70
71 71
72 #define NGX_HTTP_PROXY_PARSE_NO_HEADER 20 72 #define NGX_HTTP_PROXY_PARSE_NO_HEADER 20
73 73
405 return NGX_HTTP_INTERNAL_SERVER_ERROR; 405 return NGX_HTTP_INTERNAL_SERVER_ERROR;
406 } 406 }
407 407
408 u->peer.log = r->connection->log; 408 u->peer.log = r->connection->log;
409 u->peer.log_error = NGX_ERROR_ERR; 409 u->peer.log_error = NGX_ERROR_ERR;
410 u->peer.peers = plcf->peers; 410 u->peer.peers = plcf->upstream_peers->peers;
411 u->peer.tries = plcf->peers->number; 411 u->peer.tries = plcf->upstream_peers->peers->number;
412 #if (NGX_THREADS) 412 #if (NGX_THREADS)
413 u->peer.lock = &r->connection->lock; 413 u->peer.lock = &r->connection->lock;
414 #endif 414 #endif
415 415
416 u->output.tag = (ngx_buf_tag_t) &ngx_http_proxy_module; 416 u->output.tag = (ngx_buf_tag_t) &ngx_http_proxy_module;
1638 prev->upstream.max_fails, 1); 1638 prev->upstream.max_fails, 1);
1639 1639
1640 ngx_conf_merge_sec_value(conf->upstream.fail_timeout, 1640 ngx_conf_merge_sec_value(conf->upstream.fail_timeout,
1641 prev->upstream.fail_timeout, 10); 1641 prev->upstream.fail_timeout, 10);
1642 1642
1643 if (conf->peers && conf->peers->number > 1) { 1643 if (conf->upstream_peers && !conf->upstream_peers->balanced) {
1644 for (i = 0; i < conf->peers->number; i++) { 1644 for (i = 0; i < conf->upstream_peers->peers->number; i++) {
1645 conf->peers->peer[i].weight = 1; 1645 conf->upstream_peers->peers->peer[i].weight = 1;
1646 conf->peers->peer[i].max_fails = conf->upstream.max_fails; 1646 conf->upstream_peers->peers->peer[i].max_fails =
1647 conf->peers->peer[i].fail_timeout = conf->upstream.fail_timeout; 1647 conf->upstream.max_fails;
1648 conf->upstream_peers->peers->peer[i].fail_timeout =
1649 conf->upstream.fail_timeout;
1648 } 1650 }
1649 } 1651 }
1650 1652
1651 ngx_conf_merge_path_value(conf->upstream.temp_path, 1653 ngx_conf_merge_path_value(conf->upstream.temp_path,
1652 prev->upstream.temp_path, 1654 prev->upstream.temp_path,
1795 return NGX_CONF_ERROR; 1797 return NGX_CONF_ERROR;
1796 } 1798 }
1797 1799
1798 peers: 1800 peers:
1799 1801
1800 if (conf->peers == NULL) { 1802 if (conf->upstream_peers == NULL) {
1801 conf->peers = prev->peers; 1803 conf->upstream_peers = prev->upstream_peers;
1802 1804
1803 conf->host_header = prev->host_header; 1805 conf->host_header = prev->host_header;
1804 conf->port_text = prev->port_text; 1806 conf->port_text = prev->port_text;
1805 conf->upstream.schema = prev->upstream.schema; 1807 conf->upstream.schema = prev->upstream.schema;
1806 } 1808 }
2104 ngx_http_proxy_loc_conf_t *plcf = conf; 2106 ngx_http_proxy_loc_conf_t *plcf = conf;
2105 2107
2106 size_t add; 2108 size_t add;
2107 u_short port; 2109 u_short port;
2108 ngx_str_t *value, *url; 2110 ngx_str_t *value, *url;
2109 ngx_inet_upstream_t inet_upstream; 2111 ngx_url_t u;
2110 ngx_http_core_loc_conf_t *clcf; 2112 ngx_http_core_loc_conf_t *clcf;
2111 #if (NGX_HTTP_SSL) 2113 #if (NGX_HTTP_SSL)
2112 ngx_pool_cleanup_t *cln; 2114 ngx_pool_cleanup_t *cln;
2113 #endif
2114 #if (NGX_HAVE_UNIX_DOMAIN)
2115 ngx_unix_domain_upstream_t unix_upstream;
2116 #endif 2115 #endif
2117 2116
2118 if (plcf->upstream.schema.len) { 2117 if (plcf->upstream.schema.len) {
2119 return "is duplicate"; 2118 return "is duplicate";
2120 } 2119 }
2165 } else { 2164 } else {
2166 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid URL prefix"); 2165 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid URL prefix");
2167 return NGX_CONF_ERROR; 2166 return NGX_CONF_ERROR;
2168 } 2167 }
2169 2168
2170 if (ngx_strncasecmp(url->data + add, "unix:", 5) == 0) { 2169 ngx_memzero(&u, sizeof(ngx_url_t));
2171 2170
2172 #if (NGX_HAVE_UNIX_DOMAIN) 2171 u.url.len = url->len - add;
2173 2172 u.url.data = url->data + add;
2174 ngx_memzero(&unix_upstream, sizeof(ngx_unix_domain_upstream_t)); 2173 u.default_portn = port;
2175 2174 u.uri_part = 1;
2176 unix_upstream.name = *url; 2175 u.upstream = 1;
2177 unix_upstream.url.len = url->len - add; 2176
2178 unix_upstream.url.data = url->data + add; 2177 plcf->upstream_peers = ngx_http_upstream_add(cf, &u);
2179 unix_upstream.uri_part = 1; 2178 if (plcf->upstream_peers == NULL) {
2180
2181 plcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream);
2182 if (plcf->peers == NULL) {
2183 return NGX_CONF_ERROR;
2184 }
2185
2186 plcf->host_header.len = sizeof("localhost") - 1;
2187 plcf->host_header.data = (u_char *) "localhost";
2188 plcf->upstream.uri = unix_upstream.uri;
2189
2190 #else
2191 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2192 "the unix domain sockets are not supported "
2193 "on this platform");
2194 return NGX_CONF_ERROR; 2179 return NGX_CONF_ERROR;
2195 2180 }
2196 #endif 2181
2197 2182 plcf->host_header = u.host_header;
2198 } else { 2183 plcf->port_text = u.port;
2199 ngx_memzero(&inet_upstream, sizeof(ngx_inet_upstream_t)); 2184 plcf->upstream.uri = u.uri;
2200
2201 inet_upstream.name = *url;
2202 inet_upstream.url.len = url->len - add;
2203 inet_upstream.url.data = url->data + add;
2204 inet_upstream.default_port_value = port;
2205 inet_upstream.uri_part = 1;
2206
2207 plcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream);
2208 if (plcf->peers == NULL) {
2209 return NGX_CONF_ERROR;
2210 }
2211
2212 plcf->host_header = inet_upstream.host_header;
2213 plcf->port_text = inet_upstream.port_text;
2214 plcf->upstream.uri = inet_upstream.uri;
2215 }
2216 2185
2217 plcf->upstream.schema.len = add; 2186 plcf->upstream.schema.len = add;
2218 plcf->upstream.schema.data = url->data; 2187 plcf->upstream.schema.data = url->data;
2219 2188
2220 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); 2189 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);