comparison src/http/modules/proxy/ngx_http_proxy_handler.c @ 34:aab2ea7c0458 NGINX_0_1_17

nginx 0.1.17 *) Change: the ngx_http_rewrite_module was rewritten from the scratch. Now it is possible to redirect, to return the error codes, to check the variables and referrers. The directives can be used inside locations. The redirect directive was canceled. *) Feature: the ngx_http_geo_module. *) Feature: the proxy_set_x_var and fastcgi_set_var directives. *) Bugfix: the location configuration with "=" modifier may be used in another location. *) Bugfix: the correct content type was set only for requests that use small caps letters in extension. *) Bugfix: if the proxy_pass or fastcgi_pass directives were set in the location, and access was denied, and the error was redirected to a static page, then the segmentation fault occurred. *) Bugfix: if in a proxied "Location" header was a relative URL, then a host name and a slash were added to them; bug appeared in 0.1.14. *) Bugfix: the system error message was not logged on Linux.
author Igor Sysoev <http://sysoev.ru>
date Thu, 03 Feb 2005 00:00:00 +0300
parents da8c190bdaba
children a39d1b793287
comparison
equal deleted inserted replaced
33:27f09a550803 34:aab2ea7c0458
34 static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd, 34 static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
35 void *conf); 35 void *conf);
36 static char *ngx_http_proxy_parse_upstream(ngx_str_t *url, 36 static char *ngx_http_proxy_parse_upstream(ngx_str_t *url,
37 ngx_http_proxy_upstream_conf_t *u); 37 ngx_http_proxy_upstream_conf_t *u);
38 38
39 static char *ngx_http_proxy_set_x_var(ngx_conf_t *cf, ngx_command_t *cmd,
40 void *conf);
39 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data); 41 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data);
40 42
41 static ngx_conf_post_t ngx_http_proxy_lowat_post = 43 static ngx_conf_post_t ngx_http_proxy_lowat_post =
42 { ngx_http_proxy_lowat_check } ; 44 { ngx_http_proxy_lowat_check } ;
43 45
115 { ngx_string("proxy_set_x_real_ip"), 117 { ngx_string("proxy_set_x_real_ip"),
116 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, 118 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
117 ngx_conf_set_flag_slot, 119 ngx_conf_set_flag_slot,
118 NGX_HTTP_LOC_CONF_OFFSET, 120 NGX_HTTP_LOC_CONF_OFFSET,
119 offsetof(ngx_http_proxy_loc_conf_t, set_x_real_ip), 121 offsetof(ngx_http_proxy_loc_conf_t, set_x_real_ip),
122 NULL },
123
124 { ngx_string("proxy_set_x_var"),
125 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
126 ngx_http_proxy_set_x_var,
127 NGX_HTTP_LOC_CONF_OFFSET,
128 0,
120 NULL }, 129 NULL },
121 130
122 { ngx_string("proxy_add_x_forwarded_for"), 131 { ngx_string("proxy_add_x_forwarded_for"),
123 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, 132 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
124 ngx_conf_set_flag_slot, 133 ngx_conf_set_flag_slot,
1061 1070
1062 static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf) 1071 static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf)
1063 { 1072 {
1064 ngx_http_proxy_loc_conf_t *conf; 1073 ngx_http_proxy_loc_conf_t *conf;
1065 1074
1066 ngx_test_null(conf, 1075 if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t)))) {
1067 ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t)), 1076 return NGX_CONF_ERROR;
1068 NGX_CONF_ERROR); 1077 }
1069 1078
1070 /* 1079 /*
1071 * set by ngx_pcalloc(): 1080 * set by ngx_pcalloc():
1072 * 1081 *
1073 * conf->bufs.num = 0; 1082 * conf->bufs.num = 0;
1076 * conf->use_stale = 0; 1085 * conf->use_stale = 0;
1077 * conf->upstreams = NULL; 1086 * conf->upstreams = NULL;
1078 * conf->peers = NULL; 1087 * conf->peers = NULL;
1079 * conf->cache_path = NULL; 1088 * conf->cache_path = NULL;
1080 * conf->temp_path = NULL; 1089 * conf->temp_path = NULL;
1090 * conf->x_vars;
1081 * conf->busy_lock = NULL; 1091 * conf->busy_lock = NULL;
1082 */ 1092 */
1083 1093
1084 conf->connect_timeout = NGX_CONF_UNSET_MSEC; 1094 conf->connect_timeout = NGX_CONF_UNSET_MSEC;
1085 conf->send_timeout = NGX_CONF_UNSET_MSEC; 1095 conf->send_timeout = NGX_CONF_UNSET_MSEC;
1303 sizeof(ngx_http_proxy_upstream_conf_t)); 1313 sizeof(ngx_http_proxy_upstream_conf_t));
1304 if (lcf->upstream == NULL) { 1314 if (lcf->upstream == NULL) {
1305 return NGX_CONF_ERROR; 1315 return NGX_CONF_ERROR;
1306 } 1316 }
1307 1317
1318 lcf->upstream->url = *url;
1319
1308 if (ngx_strncasecmp(url->data + 7, "unix:", 5) == 0) { 1320 if (ngx_strncasecmp(url->data + 7, "unix:", 5) == 0) {
1309 1321
1310 #if (NGX_HAVE_UNIX_DOMAIN) 1322 #if (NGX_HAVE_UNIX_DOMAIN)
1311 1323
1312 ngx_memzero(&unix_upstream, sizeof(ngx_unix_domain_upstream_t)); 1324 ngx_memzero(&unix_upstream, sizeof(ngx_unix_domain_upstream_t));
1365 1377
1366 return NGX_CONF_OK; 1378 return NGX_CONF_OK;
1367 } 1379 }
1368 1380
1369 1381
1382 static char *ngx_http_proxy_set_x_var(ngx_conf_t *cf, ngx_command_t *cmd,
1383 void *conf)
1384 {
1385 ngx_http_proxy_loc_conf_t *lcf = conf;
1386
1387 ngx_uint_t i, *index;
1388 ngx_str_t *value;
1389 ngx_http_variable_t *var;
1390 ngx_http_core_main_conf_t *cmcf;
1391
1392 if (lcf->x_vars.elts == NULL) {
1393 if (ngx_array_init(&lcf->x_vars, cf->pool, 4,
1394 sizeof(ngx_http_variable_t *)) == NGX_ERROR)
1395 {
1396 return NGX_CONF_ERROR;
1397 }
1398 }
1399
1400 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
1401
1402 value = cf->args->elts;
1403
1404 var = cmcf->variables.elts;
1405 for (i = 0; i < cmcf->variables.nelts; i++) {
1406 if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) {
1407
1408 if (!(index = ngx_array_push(&lcf->x_vars))) {
1409 return NGX_CONF_ERROR;
1410 }
1411
1412 *index = var[i].index;
1413 return NGX_CONF_OK;
1414 }
1415 }
1416
1417 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1418 "unknown variable name \"%V\"", &value[1]);
1419 return NGX_CONF_ERROR;
1420 }
1421
1422
1370 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data) 1423 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data)
1371 { 1424 {
1372 #if (NGX_FREEBSD) 1425 #if (NGX_FREEBSD)
1373 ssize_t *np = data; 1426 ssize_t *np = data;
1374 1427