Mercurial > hg > nginx-mail
comparison src/http/ngx_http_core_module.c @ 459:dac47e9ef0d5 NGINX_0_7_27
nginx 0.7.27
*) Feature: the "try_files" directive.
*) Feature: variables support in the "fastcgi_pass" directive.
*) Feature: now the $geo variable may get an address from a
variable.
Thanks to Andrei Nigmatulin.
*) Feature: now a location's modifier may be used without space before
name.
*) Feature: the $upstream_response_length variable.
*) Bugfix: now a "add_header" directive does not add an empty value.
*) Bugfix: if zero length static file was requested, then nginx just
closed connection; the bug had appeared in 0.7.25.
*) Bugfix: a MOVE method could not move file in non-existent directory.
*) Bugfix: a segmentation fault occurred in worker process, if no one
named location was defined in server, but some one was used in an
error_page directive.
Thanks to Sergey Bochenkov.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 15 Dec 2008 00:00:00 +0300 |
parents | e7dbea1ee115 |
children | 49a0eb7ce20c |
comparison
equal
deleted
inserted
replaced
458:3b8e9d1bc9bb | 459:dac47e9ef0d5 |
---|---|
37 | 37 |
38 static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, | 38 static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, |
39 void *dummy); | 39 void *dummy); |
40 static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, | 40 static char *ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, |
41 void *dummy); | 41 void *dummy); |
42 static ngx_int_t ngx_http_core_regex_location(ngx_conf_t *cf, | |
43 ngx_http_core_loc_conf_t *clcf, ngx_str_t *regex, ngx_uint_t caseless); | |
42 | 44 |
43 static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, | 45 static char *ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, |
44 void *conf); | 46 void *conf); |
45 static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, | 47 static char *ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, |
46 void *conf); | 48 void *conf); |
53 static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, | 55 static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, |
54 void *conf); | 56 void *conf); |
55 static char *ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd, | 57 static char *ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd, |
56 void *conf); | 58 void *conf); |
57 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, | 59 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, |
60 void *conf); | |
61 static char *ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd, | |
58 void *conf); | 62 void *conf); |
59 static char *ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, | 63 static char *ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, |
60 void *conf); | 64 void *conf); |
61 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, | 65 static char *ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, |
62 void *conf); | 66 void *conf); |
535 ngx_http_core_error_page, | 539 ngx_http_core_error_page, |
536 NGX_HTTP_LOC_CONF_OFFSET, | 540 NGX_HTTP_LOC_CONF_OFFSET, |
537 0, | 541 0, |
538 NULL }, | 542 NULL }, |
539 | 543 |
544 { ngx_string("try_files"), | |
545 NGX_HTTP_LOC_CONF|NGX_CONF_2MORE, | |
546 ngx_http_core_try_files, | |
547 NGX_HTTP_LOC_CONF_OFFSET, | |
548 0, | |
549 NULL }, | |
550 | |
540 { ngx_string("post_action"), | 551 { ngx_string("post_action"), |
541 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF | 552 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
542 |NGX_CONF_TAKE1, | 553 |NGX_CONF_TAKE1, |
543 ngx_conf_set_str_slot, | 554 ngx_conf_set_str_slot, |
544 NGX_HTTP_LOC_CONF_OFFSET, | 555 NGX_HTTP_LOC_CONF_OFFSET, |
1028 return NGX_AGAIN; | 1039 return NGX_AGAIN; |
1029 } | 1040 } |
1030 | 1041 |
1031 | 1042 |
1032 ngx_int_t | 1043 ngx_int_t |
1044 ngx_http_core_try_files_phase(ngx_http_request_t *r, | |
1045 ngx_http_phase_handler_t *ph) | |
1046 { | |
1047 size_t len, root, alias; | |
1048 ssize_t reserve, allocated; | |
1049 u_char *p, *name; | |
1050 ngx_str_t path; | |
1051 ngx_http_try_file_t *tf; | |
1052 ngx_open_file_info_t of; | |
1053 ngx_http_script_code_pt code; | |
1054 ngx_http_script_engine_t e; | |
1055 ngx_http_core_loc_conf_t *clcf; | |
1056 ngx_http_script_len_code_pt lcode; | |
1057 | |
1058 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1059 "try files phase: %ui", r->phase_handler); | |
1060 | |
1061 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
1062 | |
1063 if (clcf->try_files == NULL) { | |
1064 r->phase_handler++; | |
1065 return NGX_AGAIN; | |
1066 } | |
1067 | |
1068 allocated = 0; | |
1069 root = 0; | |
1070 name = NULL; | |
1071 path.len = 0; | |
1072 path.data = NULL; | |
1073 | |
1074 tf = clcf->try_files; | |
1075 | |
1076 alias = clcf->alias ? clcf->name.len : 0; | |
1077 | |
1078 for ( ;; ) { | |
1079 | |
1080 if (tf->lengths) { | |
1081 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); | |
1082 | |
1083 e.ip = tf->lengths->elts; | |
1084 e.request = r; | |
1085 e.flushed = 1; | |
1086 | |
1087 /* 1 is for terminating '\0' as in static names */ | |
1088 len = 1; | |
1089 | |
1090 while (*(uintptr_t *) e.ip) { | |
1091 lcode = *(ngx_http_script_len_code_pt *) e.ip; | |
1092 len += lcode(&e); | |
1093 } | |
1094 | |
1095 } else { | |
1096 len = tf->name.len; | |
1097 } | |
1098 | |
1099 reserve = len - r->uri.len; | |
1100 | |
1101 /* 16 bytes are preallocation */ | |
1102 reserve = reserve < 16 ? 16 : reserve + 16; | |
1103 | |
1104 reserve += alias; | |
1105 | |
1106 if (reserve > allocated) { | |
1107 | |
1108 /* we just need to allocate path and to copy a root */ | |
1109 | |
1110 if (ngx_http_map_uri_to_path(r, &path, &root, reserve) == NULL) { | |
1111 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1112 return NGX_OK; | |
1113 } | |
1114 | |
1115 name = path.data + root; | |
1116 allocated = path.len - root - (r->uri.len - alias); | |
1117 } | |
1118 | |
1119 if (tf->values == NULL) { | |
1120 | |
1121 /* tf->name.len includes the terminating '\0' */ | |
1122 | |
1123 ngx_memcpy(name, tf->name.data, tf->name.len); | |
1124 | |
1125 path.len = (name + tf->name.len - 1) - path.data; | |
1126 | |
1127 } else { | |
1128 e.ip = tf->values->elts; | |
1129 e.pos = name; | |
1130 | |
1131 while (*(uintptr_t *) e.ip) { | |
1132 code = *(ngx_http_script_code_pt *) e.ip; | |
1133 code((ngx_http_script_engine_t *) &e); | |
1134 } | |
1135 | |
1136 path.len = e.pos - path.data; | |
1137 | |
1138 *e.pos++ = '\0'; | |
1139 | |
1140 if (alias && ngx_strncmp(name, clcf->name.data, alias) == 0) { | |
1141 ngx_memcpy(name, name + alias, len - alias); | |
1142 path.len -= alias; | |
1143 } | |
1144 } | |
1145 | |
1146 tf++; | |
1147 | |
1148 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1149 "try to use file: \"%s\"", name); | |
1150 | |
1151 if (tf->lengths == NULL && tf->name.len == 0) { | |
1152 | |
1153 path.len -= root; | |
1154 path.data += root; | |
1155 | |
1156 if (path.data[0] == '@') { | |
1157 (void) ngx_http_named_location(r, &path); | |
1158 | |
1159 } else { | |
1160 (void) ngx_http_internal_redirect(r, &path, NULL); | |
1161 } | |
1162 | |
1163 return NGX_OK; | |
1164 } | |
1165 | |
1166 ngx_memzero(&of, sizeof(ngx_open_file_info_t)); | |
1167 | |
1168 of.directio = clcf->directio; | |
1169 of.valid = clcf->open_file_cache_valid; | |
1170 of.min_uses = clcf->open_file_cache_min_uses; | |
1171 of.errors = clcf->open_file_cache_errors; | |
1172 of.events = clcf->open_file_cache_events; | |
1173 | |
1174 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) | |
1175 != NGX_OK) | |
1176 { | |
1177 if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR) { | |
1178 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err, | |
1179 ngx_open_file_n " \"%s\" failed", path.data); | |
1180 } | |
1181 | |
1182 continue; | |
1183 } | |
1184 | |
1185 path.len -= root; | |
1186 path.data += root; | |
1187 | |
1188 if (!alias) { | |
1189 r->uri = path; | |
1190 | |
1191 } else { | |
1192 r->uri.len = alias + path.len; | |
1193 r->uri.data = ngx_pnalloc(r->pool, r->uri.len); | |
1194 if (r->uri.data == NULL) { | |
1195 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | |
1196 return NGX_OK; | |
1197 } | |
1198 | |
1199 p = ngx_copy(r->uri.data, clcf->name.data, alias); | |
1200 ngx_memcpy(p, name, path.len); | |
1201 } | |
1202 | |
1203 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1204 "try file uri: \"%V\"", &r->uri); | |
1205 | |
1206 r->phase_handler++; | |
1207 return NGX_AGAIN; | |
1208 } | |
1209 | |
1210 /* not reached */ | |
1211 } | |
1212 | |
1213 | |
1214 ngx_int_t | |
1033 ngx_http_core_content_phase(ngx_http_request_t *r, | 1215 ngx_http_core_content_phase(ngx_http_request_t *r, |
1034 ngx_http_phase_handler_t *ph) | 1216 ngx_http_phase_handler_t *ph) |
1035 { | 1217 { |
1036 size_t root; | 1218 size_t root; |
1037 ngx_int_t rc; | 1219 ngx_int_t rc; |
2013 ngx_http_core_loc_conf_t **clcfp; | 2195 ngx_http_core_loc_conf_t **clcfp; |
2014 ngx_http_core_main_conf_t *cmcf; | 2196 ngx_http_core_main_conf_t *cmcf; |
2015 | 2197 |
2016 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | 2198 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
2017 | 2199 |
2018 for (clcfp = cscf->named_locations; *clcfp; clcfp++) { | 2200 if (cscf->named_locations) { |
2019 | 2201 |
2020 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 2202 for (clcfp = cscf->named_locations; *clcfp; clcfp++) { |
2021 "test location: \"%V\"", &(*clcfp)->name); | 2203 |
2022 | 2204 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2023 if (name->len != (*clcfp)->name.len | 2205 "test location: \"%V\"", &(*clcfp)->name); |
2024 || ngx_strncmp(name->data, (*clcfp)->name.data, name->len) != 0) | 2206 |
2025 { | 2207 if (name->len != (*clcfp)->name.len |
2026 continue; | 2208 || ngx_strncmp(name->data, (*clcfp)->name.data, name->len) != 0) |
2027 } | 2209 { |
2028 | 2210 continue; |
2029 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 2211 } |
2030 "using location: %V \"%V?%V\"", name, &r->uri, &r->args); | 2212 |
2031 | 2213 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2032 r->internal = 1; | 2214 "using location: %V \"%V?%V\"", |
2033 r->content_handler = NULL; | 2215 name, &r->uri, &r->args); |
2034 r->loc_conf = (*clcfp)->loc_conf; | 2216 |
2035 | 2217 r->internal = 1; |
2036 ngx_http_update_location_config(r); | 2218 r->content_handler = NULL; |
2037 | 2219 r->loc_conf = (*clcfp)->loc_conf; |
2038 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | 2220 |
2039 | 2221 ngx_http_update_location_config(r); |
2040 r->phase_handler = cmcf->phase_engine.location_rewrite_index; | 2222 |
2041 | 2223 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); |
2042 ngx_http_core_run_phases(r); | 2224 |
2043 | 2225 r->phase_handler = cmcf->phase_engine.location_rewrite_index; |
2044 return NGX_DONE; | 2226 |
2227 ngx_http_core_run_phases(r); | |
2228 | |
2229 return NGX_DONE; | |
2230 } | |
2045 } | 2231 } |
2046 | 2232 |
2047 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 2233 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
2048 "could not find named location \"%V\"", name); | 2234 "could not find named location \"%V\"", name); |
2049 | 2235 |
2180 | 2366 |
2181 static char * | 2367 static char * |
2182 ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) | 2368 ngx_http_core_location(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy) |
2183 { | 2369 { |
2184 char *rv; | 2370 char *rv; |
2371 u_char *mod; | |
2372 size_t len; | |
2373 ngx_str_t *value, *name; | |
2185 ngx_uint_t i; | 2374 ngx_uint_t i; |
2186 ngx_str_t *value; | |
2187 ngx_conf_t save; | 2375 ngx_conf_t save; |
2188 ngx_http_module_t *module; | 2376 ngx_http_module_t *module; |
2189 ngx_http_conf_ctx_t *ctx, *pctx; | 2377 ngx_http_conf_ctx_t *ctx, *pctx; |
2190 ngx_http_core_loc_conf_t *clcf, *pclcf; | 2378 ngx_http_core_loc_conf_t *clcf, *pclcf; |
2191 | 2379 |
2223 clcf->loc_conf = ctx->loc_conf; | 2411 clcf->loc_conf = ctx->loc_conf; |
2224 | 2412 |
2225 value = cf->args->elts; | 2413 value = cf->args->elts; |
2226 | 2414 |
2227 if (cf->args->nelts == 3) { | 2415 if (cf->args->nelts == 3) { |
2228 if (value[1].len == 1 && value[1].data[0] == '=') { | 2416 |
2229 clcf->name = value[2]; | 2417 len = value[1].len; |
2418 mod = value[1].data; | |
2419 name = &value[2]; | |
2420 | |
2421 if (len == 1 && mod[0] == '=') { | |
2422 | |
2423 clcf->name = *name; | |
2230 clcf->exact_match = 1; | 2424 clcf->exact_match = 1; |
2231 | 2425 |
2232 } else if (value[1].len == 2 | 2426 } else if (len == 2 && mod[0] == '^' && mod[1] == '~') { |
2233 && value[1].data[0] == '^' | 2427 |
2234 && value[1].data[1] == '~') | 2428 clcf->name = *name; |
2235 { | |
2236 clcf->name = value[2]; | |
2237 clcf->noregex = 1; | 2429 clcf->noregex = 1; |
2238 | 2430 |
2239 } else if ((value[1].len == 1 && value[1].data[0] == '~') | 2431 } else if (len == 1 && mod[0] == '~') { |
2240 || (value[1].len == 2 | 2432 |
2241 && value[1].data[0] == '~' | 2433 if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) { |
2242 && value[1].data[1] == '*')) | |
2243 { | |
2244 #if (NGX_PCRE) | |
2245 ngx_str_t err; | |
2246 u_char errstr[NGX_MAX_CONF_ERRSTR]; | |
2247 | |
2248 err.len = NGX_MAX_CONF_ERRSTR; | |
2249 err.data = errstr; | |
2250 | |
2251 clcf->regex = ngx_regex_compile(&value[2], | |
2252 value[1].len == 2 ? NGX_REGEX_CASELESS: 0, | |
2253 cf->pool, &err); | |
2254 | |
2255 if (clcf->regex == NULL) { | |
2256 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); | |
2257 return NGX_CONF_ERROR; | 2434 return NGX_CONF_ERROR; |
2258 } | 2435 } |
2259 | 2436 |
2260 clcf->name = value[2]; | 2437 } else if (len == 2 && mod[0] == '~' && mod[1] == '*') { |
2261 #else | 2438 |
2262 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 2439 if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) { |
2263 "the using of the regex \"%V\" " | 2440 return NGX_CONF_ERROR; |
2264 "requires PCRE library", &value[2]); | 2441 } |
2265 return NGX_CONF_ERROR; | |
2266 #endif | |
2267 | 2442 |
2268 } else { | 2443 } else { |
2269 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 2444 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2270 "invalid location modifier \"%V\"", &value[1]); | 2445 "invalid location modifier \"%V\"", &value[1]); |
2271 return NGX_CONF_ERROR; | 2446 return NGX_CONF_ERROR; |
2272 } | 2447 } |
2273 | 2448 |
2274 } else { | 2449 } else { |
2275 | 2450 |
2276 clcf->name = value[1]; | 2451 name = &value[1]; |
2277 | 2452 |
2278 if (value[1].data[0] == '@') { | 2453 if (name->data[0] == '=') { |
2279 clcf->named = 1; | 2454 |
2455 clcf->name.len = name->len - 1; | |
2456 clcf->name.data = name->data + 1; | |
2457 clcf->exact_match = 1; | |
2458 | |
2459 } else if (name->data[0] == '^' && name->data[1] == '~') { | |
2460 | |
2461 clcf->name.len = name->len - 2; | |
2462 clcf->name.data = name->data + 2; | |
2463 clcf->noregex = 1; | |
2464 | |
2465 } else if (name->data[0] == '~') { | |
2466 | |
2467 name->len--; | |
2468 name->data++; | |
2469 | |
2470 if (name->data[0] == '*') { | |
2471 | |
2472 name->len--; | |
2473 name->data++; | |
2474 | |
2475 if (ngx_http_core_regex_location(cf, clcf, name, 1) != NGX_OK) { | |
2476 return NGX_CONF_ERROR; | |
2477 } | |
2478 | |
2479 } else { | |
2480 if (ngx_http_core_regex_location(cf, clcf, name, 0) != NGX_OK) { | |
2481 return NGX_CONF_ERROR; | |
2482 } | |
2483 } | |
2484 | |
2485 } else { | |
2486 | |
2487 clcf->name = *name; | |
2488 | |
2489 if (name->data[0] == '@') { | |
2490 clcf->named = 1; | |
2491 } | |
2280 } | 2492 } |
2281 } | 2493 } |
2282 | 2494 |
2283 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index]; | 2495 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index]; |
2284 | 2496 |
2312 "on server level only", | 2524 "on server level only", |
2313 &clcf->name); | 2525 &clcf->name); |
2314 return NGX_CONF_ERROR; | 2526 return NGX_CONF_ERROR; |
2315 } | 2527 } |
2316 | 2528 |
2529 len = pclcf->name.len; | |
2530 | |
2317 #if (NGX_PCRE) | 2531 #if (NGX_PCRE) |
2318 if (clcf->regex == NULL | 2532 if (clcf->regex == NULL |
2319 && ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len) | 2533 && ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0) |
2320 != 0) | |
2321 #else | 2534 #else |
2322 if (ngx_strncmp(clcf->name.data, pclcf->name.data, pclcf->name.len) | 2535 if (ngx_strncmp(clcf->name.data, pclcf->name.data, len) != 0) |
2323 != 0) | |
2324 #endif | 2536 #endif |
2325 { | 2537 { |
2326 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 2538 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2327 "location \"%V\" is outside location \"%V\"", | 2539 "location \"%V\" is outside location \"%V\"", |
2328 &clcf->name, &pclcf->name); | 2540 &clcf->name, &pclcf->name); |
2341 rv = ngx_conf_parse(cf, NULL); | 2553 rv = ngx_conf_parse(cf, NULL); |
2342 | 2554 |
2343 *cf = save; | 2555 *cf = save; |
2344 | 2556 |
2345 return rv; | 2557 return rv; |
2558 } | |
2559 | |
2560 | |
2561 static ngx_int_t | |
2562 ngx_http_core_regex_location(ngx_conf_t *cf, ngx_http_core_loc_conf_t *clcf, | |
2563 ngx_str_t *regex, ngx_uint_t caseless) | |
2564 { | |
2565 #if (NGX_PCRE) | |
2566 ngx_str_t err; | |
2567 u_char errstr[NGX_MAX_CONF_ERRSTR]; | |
2568 | |
2569 err.len = NGX_MAX_CONF_ERRSTR; | |
2570 err.data = errstr; | |
2571 | |
2572 clcf->regex = ngx_regex_compile(regex, caseless ? NGX_REGEX_CASELESS: 0, | |
2573 cf->pool, &err); | |
2574 | |
2575 if (clcf->regex == NULL) { | |
2576 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); | |
2577 return NGX_ERROR; | |
2578 } | |
2579 | |
2580 clcf->name = *regex; | |
2581 | |
2582 return NGX_OK; | |
2583 | |
2584 #else | |
2585 | |
2586 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2587 "the using of the regex \"%V\" requires PCRE library", | |
2588 regex); | |
2589 return NGX_ERROR; | |
2590 | |
2591 #endif | |
2346 } | 2592 } |
2347 | 2593 |
2348 | 2594 |
2349 static char * | 2595 static char * |
2350 ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 2596 ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
2642 * lcf->post_action = { 0, NULL }; | 2888 * lcf->post_action = { 0, NULL }; |
2643 * lcf->types = NULL; | 2889 * lcf->types = NULL; |
2644 * lcf->default_type = { 0, NULL }; | 2890 * lcf->default_type = { 0, NULL }; |
2645 * lcf->err_log = NULL; | 2891 * lcf->err_log = NULL; |
2646 * lcf->error_pages = NULL; | 2892 * lcf->error_pages = NULL; |
2893 * lcf->try_files = NULL; | |
2647 * lcf->client_body_path = NULL; | 2894 * lcf->client_body_path = NULL; |
2648 * lcf->regex = NULL; | 2895 * lcf->regex = NULL; |
2649 * lcf->exact_match = 0; | 2896 * lcf->exact_match = 0; |
2650 * lcf->auto_redirect = 0; | 2897 * lcf->auto_redirect = 0; |
2651 * lcf->alias = 0; | 2898 * lcf->alias = 0; |
3617 return NGX_CONF_OK; | 3864 return NGX_CONF_OK; |
3618 } | 3865 } |
3619 | 3866 |
3620 | 3867 |
3621 static char * | 3868 static char * |
3869 ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
3870 { | |
3871 ngx_http_core_loc_conf_t *clcf = conf; | |
3872 | |
3873 ngx_str_t *value; | |
3874 ngx_uint_t i, n; | |
3875 ngx_http_try_file_t *tf; | |
3876 ngx_http_script_compile_t sc; | |
3877 ngx_http_core_main_conf_t *cmcf; | |
3878 | |
3879 if (clcf->try_files) { | |
3880 return "is duplicate"; | |
3881 } | |
3882 | |
3883 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
3884 | |
3885 cmcf->try_files = 1; | |
3886 | |
3887 tf = ngx_pcalloc(cf->pool, cf->args->nelts * sizeof(ngx_http_try_file_t)); | |
3888 if (tf == NULL) { | |
3889 return NGX_CONF_ERROR; | |
3890 } | |
3891 | |
3892 clcf->try_files = tf; | |
3893 | |
3894 value = cf->args->elts; | |
3895 | |
3896 for (i = 0; i < cf->args->nelts - 1; i++) { | |
3897 | |
3898 tf[i].name = value[i + 1]; | |
3899 | |
3900 n = ngx_http_script_variables_count(&tf[i].name); | |
3901 | |
3902 if (n) { | |
3903 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
3904 | |
3905 sc.cf = cf; | |
3906 sc.source = &tf[i].name; | |
3907 sc.lengths = &tf[i].lengths; | |
3908 sc.values = &tf[i].values; | |
3909 sc.variables = n; | |
3910 sc.complete_lengths = 1; | |
3911 sc.complete_values = 1; | |
3912 | |
3913 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
3914 return NGX_CONF_ERROR; | |
3915 } | |
3916 | |
3917 } else { | |
3918 /* add trailing '\0' to length */ | |
3919 tf[i].name.len++; | |
3920 } | |
3921 } | |
3922 | |
3923 return NGX_CONF_OK; | |
3924 } | |
3925 | |
3926 | |
3927 static char * | |
3622 ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 3928 ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
3623 { | 3929 { |
3624 ngx_http_core_loc_conf_t *lcf = conf; | 3930 ngx_http_core_loc_conf_t *lcf = conf; |
3625 | 3931 |
3626 time_t inactive; | 3932 time_t inactive; |