Mercurial > hg > nginx
comparison src/stream/ngx_stream_proxy_module.c @ 6183:4dcffe43a7ea
Stream: the "proxy_bind" directive.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Tue, 16 Jun 2015 09:02:45 +0300 |
parents | 68c106e6fa0a |
children | fa663739e115 |
comparison
equal
deleted
inserted
replaced
6182:07e416ece597 | 6183:4dcffe43a7ea |
---|---|
19 ngx_msec_t next_upstream_timeout; | 19 ngx_msec_t next_upstream_timeout; |
20 size_t downstream_buf_size; | 20 size_t downstream_buf_size; |
21 size_t upstream_buf_size; | 21 size_t upstream_buf_size; |
22 ngx_uint_t next_upstream_tries; | 22 ngx_uint_t next_upstream_tries; |
23 ngx_flag_t next_upstream; | 23 ngx_flag_t next_upstream; |
24 ngx_addr_t *local; | |
24 | 25 |
25 #if (NGX_STREAM_SSL) | 26 #if (NGX_STREAM_SSL) |
26 ngx_flag_t ssl_enable; | 27 ngx_flag_t ssl_enable; |
27 ngx_flag_t ssl_session_reuse; | 28 ngx_flag_t ssl_session_reuse; |
28 ngx_uint_t ssl_protocols; | 29 ngx_uint_t ssl_protocols; |
62 static void *ngx_stream_proxy_create_srv_conf(ngx_conf_t *cf); | 63 static void *ngx_stream_proxy_create_srv_conf(ngx_conf_t *cf); |
63 static char *ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent, | 64 static char *ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent, |
64 void *child); | 65 void *child); |
65 static char *ngx_stream_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, | 66 static char *ngx_stream_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, |
66 void *conf); | 67 void *conf); |
68 static char *ngx_stream_proxy_bind(ngx_conf_t *cf, ngx_command_t *cmd, | |
69 void *conf); | |
67 | 70 |
68 #if (NGX_STREAM_SSL) | 71 #if (NGX_STREAM_SSL) |
69 | 72 |
70 static char *ngx_stream_proxy_ssl_password_file(ngx_conf_t *cf, | 73 static char *ngx_stream_proxy_ssl_password_file(ngx_conf_t *cf, |
71 ngx_command_t *cmd, void *conf); | 74 ngx_command_t *cmd, void *conf); |
91 static ngx_command_t ngx_stream_proxy_commands[] = { | 94 static ngx_command_t ngx_stream_proxy_commands[] = { |
92 | 95 |
93 { ngx_string("proxy_pass"), | 96 { ngx_string("proxy_pass"), |
94 NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | 97 NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, |
95 ngx_stream_proxy_pass, | 98 ngx_stream_proxy_pass, |
99 NGX_STREAM_SRV_CONF_OFFSET, | |
100 0, | |
101 NULL }, | |
102 | |
103 { ngx_string("proxy_bind"), | |
104 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
105 ngx_stream_proxy_bind, | |
96 NGX_STREAM_SRV_CONF_OFFSET, | 106 NGX_STREAM_SRV_CONF_OFFSET, |
97 0, | 107 0, |
98 NULL }, | 108 NULL }, |
99 | 109 |
100 { ngx_string("proxy_connect_timeout"), | 110 { ngx_string("proxy_connect_timeout"), |
299 s->log_handler = ngx_stream_proxy_log_error; | 309 s->log_handler = ngx_stream_proxy_log_error; |
300 | 310 |
301 u->peer.log = c->log; | 311 u->peer.log = c->log; |
302 u->peer.log_error = NGX_ERROR_ERR; | 312 u->peer.log_error = NGX_ERROR_ERR; |
303 | 313 |
314 u->peer.local = pscf->local; | |
315 | |
304 uscf = pscf->upstream; | 316 uscf = pscf->upstream; |
305 | 317 |
306 if (uscf->peer.init(s, uscf) != NGX_OK) { | 318 if (uscf->peer.init(s, uscf) != NGX_OK) { |
307 ngx_stream_proxy_finalize(s, NGX_ERROR); | 319 ngx_stream_proxy_finalize(s, NGX_ERROR); |
308 return; | 320 return; |
1091 conf->next_upstream_timeout = NGX_CONF_UNSET_MSEC; | 1103 conf->next_upstream_timeout = NGX_CONF_UNSET_MSEC; |
1092 conf->downstream_buf_size = NGX_CONF_UNSET_SIZE; | 1104 conf->downstream_buf_size = NGX_CONF_UNSET_SIZE; |
1093 conf->upstream_buf_size = NGX_CONF_UNSET_SIZE; | 1105 conf->upstream_buf_size = NGX_CONF_UNSET_SIZE; |
1094 conf->next_upstream_tries = NGX_CONF_UNSET_UINT; | 1106 conf->next_upstream_tries = NGX_CONF_UNSET_UINT; |
1095 conf->next_upstream = NGX_CONF_UNSET; | 1107 conf->next_upstream = NGX_CONF_UNSET; |
1108 conf->local = NGX_CONF_UNSET_PTR; | |
1096 | 1109 |
1097 #if (NGX_STREAM_SSL) | 1110 #if (NGX_STREAM_SSL) |
1098 conf->ssl_enable = NGX_CONF_UNSET; | 1111 conf->ssl_enable = NGX_CONF_UNSET; |
1099 conf->ssl_session_reuse = NGX_CONF_UNSET; | 1112 conf->ssl_session_reuse = NGX_CONF_UNSET; |
1100 conf->ssl_server_name = NGX_CONF_UNSET; | 1113 conf->ssl_server_name = NGX_CONF_UNSET; |
1131 ngx_conf_merge_uint_value(conf->next_upstream_tries, | 1144 ngx_conf_merge_uint_value(conf->next_upstream_tries, |
1132 prev->next_upstream_tries, 0); | 1145 prev->next_upstream_tries, 0); |
1133 | 1146 |
1134 ngx_conf_merge_value(conf->next_upstream, prev->next_upstream, 1); | 1147 ngx_conf_merge_value(conf->next_upstream, prev->next_upstream, 1); |
1135 | 1148 |
1149 ngx_conf_merge_ptr_value(conf->local, prev->local, NULL); | |
1150 | |
1136 #if (NGX_STREAM_SSL) | 1151 #if (NGX_STREAM_SSL) |
1137 | 1152 |
1138 ngx_conf_merge_value(conf->ssl_enable, prev->ssl_enable, 0); | 1153 ngx_conf_merge_value(conf->ssl_enable, prev->ssl_enable, 0); |
1139 | 1154 |
1140 ngx_conf_merge_value(conf->ssl_session_reuse, | 1155 ngx_conf_merge_value(conf->ssl_session_reuse, |
1288 return NGX_CONF_ERROR; | 1303 return NGX_CONF_ERROR; |
1289 } | 1304 } |
1290 | 1305 |
1291 return NGX_CONF_OK; | 1306 return NGX_CONF_OK; |
1292 } | 1307 } |
1308 | |
1309 | |
1310 static char * | |
1311 ngx_stream_proxy_bind(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1312 { | |
1313 ngx_stream_proxy_srv_conf_t *pscf = conf; | |
1314 | |
1315 ngx_int_t rc; | |
1316 ngx_str_t *value; | |
1317 | |
1318 if (pscf->local != NGX_CONF_UNSET_PTR) { | |
1319 return "is duplicate"; | |
1320 } | |
1321 | |
1322 value = cf->args->elts; | |
1323 | |
1324 if (ngx_strcmp(value[1].data, "off") == 0) { | |
1325 pscf->local = NULL; | |
1326 return NGX_CONF_OK; | |
1327 } | |
1328 | |
1329 pscf->local = ngx_palloc(cf->pool, sizeof(ngx_addr_t)); | |
1330 if (pscf->local == NULL) { | |
1331 return NGX_CONF_ERROR; | |
1332 } | |
1333 | |
1334 rc = ngx_parse_addr(cf->pool, pscf->local, value[1].data, value[1].len); | |
1335 | |
1336 switch (rc) { | |
1337 case NGX_OK: | |
1338 pscf->local->name = value[1]; | |
1339 return NGX_CONF_OK; | |
1340 | |
1341 case NGX_DECLINED: | |
1342 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1343 "invalid address \"%V\"", &value[1]); | |
1344 /* fall through */ | |
1345 | |
1346 default: | |
1347 return NGX_CONF_ERROR; | |
1348 } | |
1349 } |