Mercurial > hg > nginx-mail
comparison src/http/ngx_http_core_module.c @ 665:0b460e61bdcd default tip
Merge with nginx 1.0.0.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 25 Apr 2011 04:22:17 +0400 |
parents | b4dcae568a2a |
children |
comparison
equal
deleted
inserted
replaced
572:06419a2298a9 | 665:0b460e61bdcd |
---|---|
131 { ngx_string("before"), NGX_HTTP_IMS_BEFORE }, | 131 { ngx_string("before"), NGX_HTTP_IMS_BEFORE }, |
132 { ngx_null_string, 0 } | 132 { ngx_null_string, 0 } |
133 }; | 133 }; |
134 | 134 |
135 | 135 |
136 static ngx_conf_enum_t ngx_http_core_keepalive_disable[] = { | |
137 { ngx_string("none"), NGX_HTTP_KEEPALIVE_DISABLE_NONE }, | |
138 { ngx_string("msie6"), NGX_HTTP_KEEPALIVE_DISABLE_MSIE6 }, | |
139 { ngx_string("safari"), NGX_HTTP_KEEPALIVE_DISABLE_SAFARI }, | |
140 { ngx_null_string, 0 } | |
141 }; | |
142 | |
143 | |
136 static ngx_path_init_t ngx_http_client_temp_path = { | 144 static ngx_path_init_t ngx_http_client_temp_path = { |
137 ngx_string(NGX_HTTP_CLIENT_TEMP_PATH), { 0, 0, 0 } | 145 ngx_string(NGX_HTTP_CLIENT_TEMP_PATH), { 0, 0, 0 } |
138 }; | 146 }; |
139 | 147 |
140 | 148 |
406 offsetof(ngx_http_core_loc_conf_t, aio), | 414 offsetof(ngx_http_core_loc_conf_t, aio), |
407 &ngx_http_core_aio }, | 415 &ngx_http_core_aio }, |
408 | 416 |
409 #endif | 417 #endif |
410 | 418 |
419 { ngx_string("read_ahead"), | |
420 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
421 ngx_conf_set_size_slot, | |
422 NGX_HTTP_LOC_CONF_OFFSET, | |
423 offsetof(ngx_http_core_loc_conf_t, read_ahead), | |
424 NULL }, | |
425 | |
411 { ngx_string("directio"), | 426 { ngx_string("directio"), |
412 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 427 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
413 ngx_http_core_directio, | 428 ngx_http_core_directio, |
414 NGX_HTTP_LOC_CONF_OFFSET, | 429 NGX_HTTP_LOC_CONF_OFFSET, |
415 0, | 430 0, |
485 ngx_conf_set_num_slot, | 500 ngx_conf_set_num_slot, |
486 NGX_HTTP_LOC_CONF_OFFSET, | 501 NGX_HTTP_LOC_CONF_OFFSET, |
487 offsetof(ngx_http_core_loc_conf_t, keepalive_requests), | 502 offsetof(ngx_http_core_loc_conf_t, keepalive_requests), |
488 NULL }, | 503 NULL }, |
489 | 504 |
505 { ngx_string("keepalive_disable"), | |
506 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
507 ngx_conf_set_enum_slot, | |
508 NGX_HTTP_LOC_CONF_OFFSET, | |
509 offsetof(ngx_http_core_loc_conf_t, keepalive_disable), | |
510 &ngx_http_core_keepalive_disable }, | |
511 | |
490 { ngx_string("satisfy"), | 512 { ngx_string("satisfy"), |
491 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 513 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
492 ngx_conf_set_enum_slot, | 514 ngx_conf_set_enum_slot, |
493 NGX_HTTP_LOC_CONF_OFFSET, | 515 NGX_HTTP_LOC_CONF_OFFSET, |
494 offsetof(ngx_http_core_loc_conf_t, satisfy), | 516 offsetof(ngx_http_core_loc_conf_t, satisfy), |
589 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 611 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
590 ngx_conf_set_enum_slot, | 612 ngx_conf_set_enum_slot, |
591 NGX_HTTP_LOC_CONF_OFFSET, | 613 NGX_HTTP_LOC_CONF_OFFSET, |
592 offsetof(ngx_http_core_loc_conf_t, if_modified_since), | 614 offsetof(ngx_http_core_loc_conf_t, if_modified_since), |
593 &ngx_http_core_if_modified_since }, | 615 &ngx_http_core_if_modified_since }, |
616 | |
617 { ngx_string("chunked_transfer_encoding"), | |
618 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
619 ngx_conf_set_flag_slot, | |
620 NGX_HTTP_LOC_CONF_OFFSET, | |
621 offsetof(ngx_http_core_loc_conf_t, chunked_transfer_encoding), | |
622 NULL }, | |
594 | 623 |
595 { ngx_string("error_page"), | 624 { ngx_string("error_page"), |
596 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF | 625 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
597 |NGX_CONF_2MORE, | 626 |NGX_CONF_2MORE, |
598 ngx_http_core_error_page, | 627 ngx_http_core_error_page, |
758 r->connection->unexpected_eof = 0; | 787 r->connection->unexpected_eof = 0; |
759 | 788 |
760 if (!r->internal) { | 789 if (!r->internal) { |
761 switch (r->headers_in.connection_type) { | 790 switch (r->headers_in.connection_type) { |
762 case 0: | 791 case 0: |
763 if (r->http_version > NGX_HTTP_VERSION_10) { | 792 r->keepalive = (r->http_version > NGX_HTTP_VERSION_10); |
764 r->keepalive = 1; | |
765 } else { | |
766 r->keepalive = 0; | |
767 } | |
768 break; | 793 break; |
769 | 794 |
770 case NGX_HTTP_CONNECTION_CLOSE: | 795 case NGX_HTTP_CONNECTION_CLOSE: |
771 r->keepalive = 0; | 796 r->keepalive = 0; |
772 break; | 797 break; |
774 case NGX_HTTP_CONNECTION_KEEP_ALIVE: | 799 case NGX_HTTP_CONNECTION_KEEP_ALIVE: |
775 r->keepalive = 1; | 800 r->keepalive = 1; |
776 break; | 801 break; |
777 } | 802 } |
778 | 803 |
779 if (r->keepalive && r->headers_in.msie && r->method == NGX_HTTP_POST) { | 804 r->lingering_close = (r->headers_in.content_length_n > 0); |
780 | |
781 /* | |
782 * MSIE may wait for some time if an response for | |
783 * a POST request was sent over a keepalive connection | |
784 */ | |
785 | |
786 r->keepalive = 0; | |
787 } | |
788 | |
789 if (r->headers_in.content_length_n > 0) { | |
790 r->lingering_close = 1; | |
791 | |
792 } else { | |
793 r->lingering_close = 0; | |
794 } | |
795 | |
796 r->phase_handler = 0; | 805 r->phase_handler = 0; |
797 | 806 |
798 } else { | 807 } else { |
799 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | 808 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); |
800 r->phase_handler = cmcf->phase_engine.server_rewrite_index; | 809 r->phase_handler = cmcf->phase_engine.server_rewrite_index; |
801 } | 810 } |
802 | 811 |
803 if (r->unparsed_uri.len) { | |
804 r->valid_unparsed_uri = 1; | |
805 } | |
806 | |
807 r->valid_location = 1; | 812 r->valid_location = 1; |
808 r->gzip = 0; | 813 #if (NGX_HTTP_GZIP) |
814 r->gzip_tested = 0; | |
815 r->gzip_ok = 0; | |
816 r->gzip_vary = 0; | |
817 #endif | |
809 | 818 |
810 r->write_event_handler = ngx_http_core_run_phases; | 819 r->write_event_handler = ngx_http_core_run_phases; |
811 ngx_http_core_run_phases(r); | 820 ngx_http_core_run_phases(r); |
812 } | 821 } |
813 | 822 |
839 { | 848 { |
840 ngx_int_t rc; | 849 ngx_int_t rc; |
841 | 850 |
842 /* | 851 /* |
843 * generic phase checker, | 852 * generic phase checker, |
844 * used by the post read, server rewrite, rewrite, and pre-access phases | 853 * used by the post read and pre-access phases |
845 */ | 854 */ |
846 | 855 |
847 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 856 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
848 "generic phase: %ui", r->phase_handler); | 857 "generic phase: %ui", r->phase_handler); |
849 | 858 |
862 if (rc == NGX_AGAIN || rc == NGX_DONE) { | 871 if (rc == NGX_AGAIN || rc == NGX_DONE) { |
863 return NGX_OK; | 872 return NGX_OK; |
864 } | 873 } |
865 | 874 |
866 /* rc == NGX_ERROR || rc == NGX_HTTP_... */ | 875 /* rc == NGX_ERROR || rc == NGX_HTTP_... */ |
876 | |
877 ngx_http_finalize_request(r, rc); | |
878 | |
879 return NGX_OK; | |
880 } | |
881 | |
882 | |
883 ngx_int_t | |
884 ngx_http_core_rewrite_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph) | |
885 { | |
886 ngx_int_t rc; | |
887 | |
888 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
889 "rewrite phase: %ui", r->phase_handler); | |
890 | |
891 rc = ph->handler(r); | |
892 | |
893 if (rc == NGX_DECLINED) { | |
894 r->phase_handler++; | |
895 return NGX_AGAIN; | |
896 } | |
897 | |
898 if (rc == NGX_DONE) { | |
899 return NGX_OK; | |
900 } | |
901 | |
902 /* NGX_OK, NGX_AGAIN, NGX_ERROR, NGX_HTTP_... */ | |
867 | 903 |
868 ngx_http_finalize_request(r, rc); | 904 ngx_http_finalize_request(r, rc); |
869 | 905 |
870 return NGX_OK; | 906 return NGX_OK; |
871 } | 907 } |
992 if (r->uri_changes == 0) { | 1028 if (r->uri_changes == 0) { |
993 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 1029 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
994 "rewrite or internal redirection cycle " | 1030 "rewrite or internal redirection cycle " |
995 "while processing \"%V\"", &r->uri); | 1031 "while processing \"%V\"", &r->uri); |
996 | 1032 |
997 r->main->count++; | |
998 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 1033 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
999 return NGX_OK; | 1034 return NGX_OK; |
1000 } | 1035 } |
1001 | 1036 |
1002 r->phase_handler = ph->next; | 1037 r->phase_handler = ph->next; |
1071 | 1106 |
1072 ngx_int_t | 1107 ngx_int_t |
1073 ngx_http_core_post_access_phase(ngx_http_request_t *r, | 1108 ngx_http_core_post_access_phase(ngx_http_request_t *r, |
1074 ngx_http_phase_handler_t *ph) | 1109 ngx_http_phase_handler_t *ph) |
1075 { | 1110 { |
1111 ngx_int_t access_code; | |
1112 | |
1076 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1113 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1077 "post access phase: %ui", r->phase_handler); | 1114 "post access phase: %ui", r->phase_handler); |
1078 | 1115 |
1079 if (r->access_code) { | 1116 access_code = r->access_code; |
1080 | 1117 |
1081 if (r->access_code == NGX_HTTP_FORBIDDEN) { | 1118 if (access_code) { |
1119 if (access_code == NGX_HTTP_FORBIDDEN) { | |
1082 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 1120 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1083 "access forbidden by rule"); | 1121 "access forbidden by rule"); |
1084 } | 1122 } |
1085 | 1123 |
1086 ngx_http_finalize_request(r, r->access_code); | 1124 r->access_code = 0; |
1125 ngx_http_finalize_request(r, access_code); | |
1087 return NGX_OK; | 1126 return NGX_OK; |
1088 } | 1127 } |
1089 | 1128 |
1090 r->phase_handler++; | 1129 r->phase_handler++; |
1091 return NGX_AGAIN; | 1130 return NGX_AGAIN; |
1123 /* suppress MSVC warning */ | 1162 /* suppress MSVC warning */ |
1124 path.data = NULL; | 1163 path.data = NULL; |
1125 | 1164 |
1126 tf = clcf->try_files; | 1165 tf = clcf->try_files; |
1127 | 1166 |
1128 alias = clcf->alias ? clcf->name.len : 0; | 1167 alias = clcf->alias; |
1129 | 1168 |
1130 for ( ;; ) { | 1169 for ( ;; ) { |
1131 | 1170 |
1132 if (tf->lengths) { | 1171 if (tf->lengths) { |
1133 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); | 1172 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); |
1184 path.len = e.pos - path.data; | 1223 path.len = e.pos - path.data; |
1185 | 1224 |
1186 *e.pos = '\0'; | 1225 *e.pos = '\0'; |
1187 | 1226 |
1188 if (alias && ngx_strncmp(name, clcf->name.data, alias) == 0) { | 1227 if (alias && ngx_strncmp(name, clcf->name.data, alias) == 0) { |
1189 ngx_memcpy(name, name + alias, len - alias); | 1228 ngx_memmove(name, name + alias, len - alias); |
1190 path.len -= alias; | 1229 path.len -= alias; |
1191 } | 1230 } |
1192 } | 1231 } |
1193 | 1232 |
1194 test_dir = tf->test_dir; | 1233 test_dir = tf->test_dir; |
1195 | 1234 |
1196 tf++; | 1235 tf++; |
1197 | 1236 |
1198 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1237 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1199 "try to use file: \"%s\" \"%s\"", name, path.data); | 1238 "try to use %s: \"%s\" \"%s\"", |
1239 test_dir ? "dir" : "file", name, path.data); | |
1200 | 1240 |
1201 if (tf->lengths == NULL && tf->name.len == 0) { | 1241 if (tf->lengths == NULL && tf->name.len == 0) { |
1202 | 1242 |
1203 if (tf->code) { | 1243 if (tf->code) { |
1204 ngx_http_finalize_request(r, tf->code); | 1244 ngx_http_finalize_request(r, tf->code); |
1231 of.events = clcf->open_file_cache_events; | 1271 of.events = clcf->open_file_cache_events; |
1232 | 1272 |
1233 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) | 1273 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
1234 != NGX_OK) | 1274 != NGX_OK) |
1235 { | 1275 { |
1236 if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR) { | 1276 if (of.err != NGX_ENOENT |
1277 && of.err != NGX_ENOTDIR | |
1278 && of.err != NGX_ENAMETOOLONG) | |
1279 { | |
1237 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err, | 1280 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err, |
1238 "%s \"%s\" failed", of.failed, path.data); | 1281 "%s \"%s\" failed", of.failed, path.data); |
1239 } | 1282 } |
1240 | 1283 |
1241 continue; | 1284 continue; |
1249 path.data += root; | 1292 path.data += root; |
1250 | 1293 |
1251 if (!alias) { | 1294 if (!alias) { |
1252 r->uri = path; | 1295 r->uri = path; |
1253 | 1296 |
1297 #if (NGX_PCRE) | |
1298 } else if (clcf->regex) { | |
1299 if (!test_dir) { | |
1300 r->uri = path; | |
1301 r->add_uri_to_alias = 1; | |
1302 } | |
1303 #endif | |
1254 } else { | 1304 } else { |
1255 r->uri.len = alias + path.len; | 1305 r->uri.len = alias + path.len; |
1256 r->uri.data = ngx_pnalloc(r->pool, r->uri.len); | 1306 r->uri.data = ngx_pnalloc(r->pool, r->uri.len); |
1257 if (r->uri.data == NULL) { | 1307 if (r->uri.data == NULL) { |
1258 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 1308 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
1309 return NGX_AGAIN; | 1359 return NGX_AGAIN; |
1310 } | 1360 } |
1311 | 1361 |
1312 /* no content handler was found */ | 1362 /* no content handler was found */ |
1313 | 1363 |
1314 if (r->uri.data[r->uri.len - 1] == '/' && !r->zero_in_uri) { | 1364 if (r->uri.data[r->uri.len - 1] == '/') { |
1315 | 1365 |
1316 if (ngx_http_map_uri_to_path(r, &path, &root, 0) != NULL) { | 1366 if (ngx_http_map_uri_to_path(r, &path, &root, 0) != NULL) { |
1317 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 1367 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1318 "directory index of \"%s\" is forbidden", path.data); | 1368 "directory index of \"%s\" is forbidden", path.data); |
1319 } | 1369 } |
1372 if (r->keepalive) { | 1422 if (r->keepalive) { |
1373 if (clcf->keepalive_timeout == 0) { | 1423 if (clcf->keepalive_timeout == 0) { |
1374 r->keepalive = 0; | 1424 r->keepalive = 0; |
1375 | 1425 |
1376 } else if (r->connection->requests >= clcf->keepalive_requests) { | 1426 } else if (r->connection->requests >= clcf->keepalive_requests) { |
1427 r->keepalive = 0; | |
1428 | |
1429 } else if (r->headers_in.msie6 | |
1430 && r->method == NGX_HTTP_POST | |
1431 && (clcf->keepalive_disable | |
1432 & NGX_HTTP_KEEPALIVE_DISABLE_MSIE6)) | |
1433 { | |
1434 /* | |
1435 * MSIE may wait for some time if an response for | |
1436 * a POST request was sent over a keepalive connection | |
1437 */ | |
1438 r->keepalive = 0; | |
1439 | |
1440 } else if (r->headers_in.safari | |
1441 && (clcf->keepalive_disable | |
1442 & NGX_HTTP_KEEPALIVE_DISABLE_SAFARI)) | |
1443 { | |
1444 /* | |
1445 * Safari may send a POST request to a closed keepalive | |
1446 * connection and may stall for some time, see | |
1447 * https://bugs.webkit.org/show_bug.cgi?id=5760 | |
1448 */ | |
1377 r->keepalive = 0; | 1449 r->keepalive = 0; |
1378 } | 1450 } |
1379 } | 1451 } |
1380 | 1452 |
1381 if (!clcf->tcp_nopush) { | 1453 if (!clcf->tcp_nopush) { |
1405 ngx_http_core_find_location(ngx_http_request_t *r) | 1477 ngx_http_core_find_location(ngx_http_request_t *r) |
1406 { | 1478 { |
1407 ngx_int_t rc; | 1479 ngx_int_t rc; |
1408 ngx_http_core_loc_conf_t *pclcf; | 1480 ngx_http_core_loc_conf_t *pclcf; |
1409 #if (NGX_PCRE) | 1481 #if (NGX_PCRE) |
1410 ngx_int_t n, len; | 1482 ngx_int_t n; |
1411 ngx_uint_t noregex; | 1483 ngx_uint_t noregex; |
1412 ngx_http_core_loc_conf_t *clcf, **clcfp; | 1484 ngx_http_core_loc_conf_t *clcf, **clcfp; |
1413 | 1485 |
1414 noregex = 0; | 1486 noregex = 0; |
1415 #endif | 1487 #endif |
1439 | 1511 |
1440 #if (NGX_PCRE) | 1512 #if (NGX_PCRE) |
1441 | 1513 |
1442 if (noregex == 0 && pclcf->regex_locations) { | 1514 if (noregex == 0 && pclcf->regex_locations) { |
1443 | 1515 |
1444 len = 0; | |
1445 | |
1446 for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) { | 1516 for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) { |
1447 | 1517 |
1448 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1518 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1449 "test location: ~ \"%V\"", &(*clcfp)->name); | 1519 "test location: ~ \"%V\"", &(*clcfp)->name); |
1450 | 1520 |
1451 if ((*clcfp)->captures) { | 1521 n = ngx_http_regex_exec(r, (*clcfp)->regex, &r->uri); |
1452 | 1522 |
1453 len = (NGX_HTTP_MAX_CAPTURES + 1) * 3; | 1523 if (n == NGX_OK) { |
1454 | 1524 r->loc_conf = (*clcfp)->loc_conf; |
1455 if (r->captures == NULL) { | 1525 |
1456 r->captures = ngx_palloc(r->pool, len * sizeof(int)); | 1526 /* look up nested locations */ |
1457 if (r->captures == NULL) { | 1527 |
1458 return NGX_ERROR; | 1528 rc = ngx_http_core_find_location(r); |
1459 } | 1529 |
1460 } | 1530 return (rc == NGX_ERROR) ? rc : NGX_OK; |
1461 } | 1531 } |
1462 | 1532 |
1463 n = ngx_regex_exec((*clcfp)->regex, &r->uri, r->captures, len); | 1533 if (n == NGX_DECLINED) { |
1464 | |
1465 if (n == NGX_REGEX_NO_MATCHED) { | |
1466 continue; | 1534 continue; |
1467 } | 1535 } |
1468 | 1536 |
1469 if (n < 0) { | 1537 return NGX_ERROR; |
1470 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
1471 ngx_regex_exec_n | |
1472 " failed: %d on \"%V\" using \"%V\"", | |
1473 n, &r->uri, &(*clcfp)->name); | |
1474 return NGX_ERROR; | |
1475 } | |
1476 | |
1477 /* match */ | |
1478 | |
1479 r->loc_conf = (*clcfp)->loc_conf; | |
1480 | |
1481 r->ncaptures = len; | |
1482 r->captures_data = r->uri.data; | |
1483 | |
1484 /* look up nested locations */ | |
1485 | |
1486 rc = ngx_http_core_find_location(r); | |
1487 | |
1488 return (rc == NGX_ERROR) ? rc : NGX_OK; | |
1489 } | 1538 } |
1490 } | 1539 } |
1491 #endif | 1540 #endif |
1492 | 1541 |
1493 return rc; | 1542 return rc; |
1554 continue; | 1603 continue; |
1555 } | 1604 } |
1556 | 1605 |
1557 if (len == (size_t) node->len) { | 1606 if (len == (size_t) node->len) { |
1558 | 1607 |
1559 r->loc_conf = (node->exact) ? node->exact->loc_conf: | 1608 if (node->exact) { |
1560 node->inclusive->loc_conf; | 1609 r->loc_conf = node->exact->loc_conf; |
1561 return NGX_OK; | 1610 return NGX_OK; |
1611 | |
1612 } else { | |
1613 r->loc_conf = node->inclusive->loc_conf; | |
1614 return NGX_AGAIN; | |
1615 } | |
1562 } | 1616 } |
1563 | 1617 |
1564 /* len < node->len */ | 1618 /* len < node->len */ |
1565 | 1619 |
1566 if (len + 1 == (size_t) node->len && node->auto_redirect) { | 1620 if (len + 1 == (size_t) node->len && node->auto_redirect) { |
1579 ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash) | 1633 ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash) |
1580 { | 1634 { |
1581 u_char c, *lowcase; | 1635 u_char c, *lowcase; |
1582 size_t len; | 1636 size_t len; |
1583 ngx_uint_t i, hash; | 1637 ngx_uint_t i, hash; |
1638 | |
1639 if (types_hash->size == 0) { | |
1640 return (void *) 4; | |
1641 } | |
1584 | 1642 |
1585 if (r->headers_out.content_type.len == 0) { | 1643 if (r->headers_out.content_type.len == 0) { |
1586 return NULL; | 1644 return NULL; |
1587 } | 1645 } |
1588 | 1646 |
1672 void | 1730 void |
1673 ngx_http_set_exten(ngx_http_request_t *r) | 1731 ngx_http_set_exten(ngx_http_request_t *r) |
1674 { | 1732 { |
1675 ngx_int_t i; | 1733 ngx_int_t i; |
1676 | 1734 |
1677 r->exten.len = 0; | 1735 ngx_str_null(&r->exten); |
1678 r->exten.data = NULL; | |
1679 | 1736 |
1680 for (i = r->uri.len - 1; i > 1; i--) { | 1737 for (i = r->uri.len - 1; i > 1; i--) { |
1681 if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') { | 1738 if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') { |
1682 | 1739 |
1683 r->exten.len = r->uri.len - i - 1; | 1740 r->exten.len = r->uri.len - i - 1; |
1689 return; | 1746 return; |
1690 } | 1747 } |
1691 } | 1748 } |
1692 | 1749 |
1693 return; | 1750 return; |
1751 } | |
1752 | |
1753 | |
1754 ngx_int_t | |
1755 ngx_http_send_response(ngx_http_request_t *r, ngx_uint_t status, | |
1756 ngx_str_t *ct, ngx_http_complex_value_t *cv) | |
1757 { | |
1758 ngx_int_t rc; | |
1759 ngx_str_t val; | |
1760 ngx_buf_t *b; | |
1761 ngx_chain_t out; | |
1762 | |
1763 r->headers_out.status = status; | |
1764 | |
1765 if (status == NGX_HTTP_NO_CONTENT) { | |
1766 r->header_only = 1; | |
1767 return ngx_http_send_header(r); | |
1768 } | |
1769 | |
1770 if (ngx_http_complex_value(r, cv, &val) != NGX_OK) { | |
1771 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1772 } | |
1773 | |
1774 if (status >= NGX_HTTP_MOVED_PERMANENTLY && status <= NGX_HTTP_SEE_OTHER) { | |
1775 | |
1776 r->headers_out.location = ngx_list_push(&r->headers_out.headers); | |
1777 if (r->headers_out.location == NULL) { | |
1778 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1779 } | |
1780 | |
1781 r->headers_out.location->hash = 1; | |
1782 ngx_str_set(&r->headers_out.location->key, "Location"); | |
1783 r->headers_out.location->value = val; | |
1784 | |
1785 return status; | |
1786 } | |
1787 | |
1788 r->headers_out.content_length_n = val.len; | |
1789 | |
1790 if (ct) { | |
1791 r->headers_out.content_type_len = ct->len; | |
1792 r->headers_out.content_type = *ct; | |
1793 | |
1794 } else { | |
1795 if (ngx_http_set_content_type(r) != NGX_OK) { | |
1796 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1797 } | |
1798 } | |
1799 | |
1800 if (r->method == NGX_HTTP_HEAD || (r != r->main && val.len == 0)) { | |
1801 return ngx_http_send_header(r); | |
1802 } | |
1803 | |
1804 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); | |
1805 if (b == NULL) { | |
1806 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
1807 } | |
1808 | |
1809 b->pos = val.data; | |
1810 b->last = val.data + val.len; | |
1811 b->memory = val.len ? 1 : 0; | |
1812 b->last_buf = (r == r->main) ? 1 : 0; | |
1813 b->last_in_chain = 1; | |
1814 | |
1815 out.buf = b; | |
1816 out.next = NULL; | |
1817 | |
1818 rc = ngx_http_send_header(r); | |
1819 | |
1820 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { | |
1821 return rc; | |
1822 } | |
1823 | |
1824 return ngx_http_output_filter(r, &out); | |
1694 } | 1825 } |
1695 | 1826 |
1696 | 1827 |
1697 ngx_int_t | 1828 ngx_int_t |
1698 ngx_http_send_header(ngx_http_request_t *r) | 1829 ngx_http_send_header(ngx_http_request_t *r) |
1736 size_t alias; | 1867 size_t alias; |
1737 ngx_http_core_loc_conf_t *clcf; | 1868 ngx_http_core_loc_conf_t *clcf; |
1738 | 1869 |
1739 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 1870 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
1740 | 1871 |
1741 alias = clcf->alias ? clcf->name.len : 0; | 1872 alias = clcf->alias; |
1742 | 1873 |
1743 if (alias && !r->valid_location) { | 1874 if (alias && !r->valid_location) { |
1744 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | 1875 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
1745 "\"alias\" could not be used in location \"%V\" " | 1876 "\"alias\" could not be used in location \"%V\" " |
1746 "where URI was rewritten", &clcf->name); | 1877 "where URI was rewritten", &clcf->name); |
1763 } else { | 1894 } else { |
1764 | 1895 |
1765 #if (NGX_PCRE) | 1896 #if (NGX_PCRE) |
1766 ngx_uint_t captures; | 1897 ngx_uint_t captures; |
1767 | 1898 |
1768 captures = alias && clcf->captures; | 1899 captures = alias && clcf->regex; |
1769 reserved += captures ? 1 : r->uri.len - alias + 1; | 1900 |
1901 reserved += captures ? r->add_uri_to_alias ? r->uri.len + 1 : 1 | |
1902 : r->uri.len - alias + 1; | |
1770 #else | 1903 #else |
1771 reserved += r->uri.len - alias + 1; | 1904 reserved += r->uri.len - alias + 1; |
1772 #endif | 1905 #endif |
1773 | 1906 |
1774 if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved, | 1907 if (ngx_http_script_run(r, path, clcf->root_lengths->elts, reserved, |
1785 *root_length = path->len - reserved; | 1918 *root_length = path->len - reserved; |
1786 last = path->data + *root_length; | 1919 last = path->data + *root_length; |
1787 | 1920 |
1788 #if (NGX_PCRE) | 1921 #if (NGX_PCRE) |
1789 if (captures) { | 1922 if (captures) { |
1790 *last = '\0'; | 1923 if (!r->add_uri_to_alias) { |
1791 return last; | 1924 *last = '\0'; |
1925 return last; | |
1926 } | |
1927 | |
1928 alias = 0; | |
1792 } | 1929 } |
1793 #endif | 1930 #endif |
1794 } | 1931 } |
1795 | 1932 |
1796 last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1); | 1933 last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1); |
1880 ngx_uint_t p; | 2017 ngx_uint_t p; |
1881 ngx_array_t *cc; | 2018 ngx_array_t *cc; |
1882 ngx_table_elt_t *e, *d; | 2019 ngx_table_elt_t *e, *d; |
1883 ngx_http_core_loc_conf_t *clcf; | 2020 ngx_http_core_loc_conf_t *clcf; |
1884 | 2021 |
1885 if (r->gzip == 1) { | 2022 r->gzip_tested = 1; |
1886 return NGX_OK; | |
1887 } | |
1888 | |
1889 if (r->gzip == 2) { | |
1890 return NGX_DECLINED; | |
1891 } | |
1892 | |
1893 r->gzip = 2; | |
1894 | 2023 |
1895 if (r != r->main | 2024 if (r != r->main |
1896 || r->headers_in.accept_encoding == NULL | 2025 || r->headers_in.accept_encoding == NULL |
1897 || ngx_strcasestrn(r->headers_in.accept_encoding->value.data, | 2026 || ngx_strcasestrn(r->headers_in.accept_encoding->value.data, |
1898 "gzip", 4 - 1) | 2027 "gzip", 4 - 1) |
2023 } | 2152 } |
2024 } | 2153 } |
2025 | 2154 |
2026 #endif | 2155 #endif |
2027 | 2156 |
2028 r->gzip = 1; | 2157 r->gzip_ok = 1; |
2029 | 2158 |
2030 return NGX_OK; | 2159 return NGX_OK; |
2031 } | 2160 } |
2032 | 2161 |
2033 #endif | 2162 #endif |
2036 ngx_int_t | 2165 ngx_int_t |
2037 ngx_http_subrequest(ngx_http_request_t *r, | 2166 ngx_http_subrequest(ngx_http_request_t *r, |
2038 ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr, | 2167 ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr, |
2039 ngx_http_post_subrequest_t *ps, ngx_uint_t flags) | 2168 ngx_http_post_subrequest_t *ps, ngx_uint_t flags) |
2040 { | 2169 { |
2170 ngx_time_t *tp; | |
2041 ngx_connection_t *c; | 2171 ngx_connection_t *c; |
2042 ngx_http_request_t *sr; | 2172 ngx_http_request_t *sr; |
2043 ngx_http_core_srv_conf_t *cscf; | 2173 ngx_http_core_srv_conf_t *cscf; |
2044 ngx_http_postponed_request_t *pr, *p; | 2174 ngx_http_postponed_request_t *pr, *p; |
2045 | 2175 |
2100 } | 2230 } |
2101 | 2231 |
2102 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | 2232 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
2103 "http subrequest \"%V?%V\"", uri, &sr->args); | 2233 "http subrequest \"%V?%V\"", uri, &sr->args); |
2104 | 2234 |
2105 sr->zero_in_uri = (flags & NGX_HTTP_ZERO_IN_URI) != 0; | |
2106 sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0; | 2235 sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0; |
2107 sr->waited = (flags & NGX_HTTP_SUBREQUEST_WAITED) != 0; | 2236 sr->waited = (flags & NGX_HTTP_SUBREQUEST_WAITED) != 0; |
2108 | 2237 |
2109 sr->unparsed_uri = r->unparsed_uri; | 2238 sr->unparsed_uri = r->unparsed_uri; |
2110 sr->method_name = ngx_http_core_get_method; | 2239 sr->method_name = ngx_http_core_get_method; |
2149 sr->expect_tested = 1; | 2278 sr->expect_tested = 1; |
2150 sr->main_filter_need_in_memory = r->main_filter_need_in_memory; | 2279 sr->main_filter_need_in_memory = r->main_filter_need_in_memory; |
2151 | 2280 |
2152 sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1; | 2281 sr->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1; |
2153 | 2282 |
2283 tp = ngx_timeofday(); | |
2284 r->start_sec = tp->sec; | |
2285 r->start_msec = tp->msec; | |
2286 | |
2154 r->main->subrequests++; | 2287 r->main->subrequests++; |
2155 r->main->count++; | 2288 r->main->count++; |
2156 | 2289 |
2157 *psr = sr; | 2290 *psr = sr; |
2158 | 2291 |
2182 | 2315 |
2183 if (args) { | 2316 if (args) { |
2184 r->args = *args; | 2317 r->args = *args; |
2185 | 2318 |
2186 } else { | 2319 } else { |
2187 r->args.len = 0; | 2320 ngx_str_null(&r->args); |
2188 r->args.data = NULL; | |
2189 } | 2321 } |
2190 | 2322 |
2191 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 2323 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2192 "internal redirect: \"%V?%V\"", uri, &r->args); | 2324 "internal redirect: \"%V?%V\"", uri, &r->args); |
2193 | 2325 |
2204 #if (NGX_HTTP_CACHE) | 2336 #if (NGX_HTTP_CACHE) |
2205 r->cache = NULL; | 2337 r->cache = NULL; |
2206 #endif | 2338 #endif |
2207 | 2339 |
2208 r->internal = 1; | 2340 r->internal = 1; |
2341 r->add_uri_to_alias = 0; | |
2209 r->main->count++; | 2342 r->main->count++; |
2210 | 2343 |
2211 ngx_http_handler(r); | 2344 ngx_http_handler(r); |
2212 | 2345 |
2213 return NGX_DONE; | 2346 return NGX_DONE; |
2307 char *rv; | 2440 char *rv; |
2308 void *mconf; | 2441 void *mconf; |
2309 ngx_uint_t i; | 2442 ngx_uint_t i; |
2310 ngx_conf_t pcf; | 2443 ngx_conf_t pcf; |
2311 ngx_http_module_t *module; | 2444 ngx_http_module_t *module; |
2445 struct sockaddr_in *sin; | |
2312 ngx_http_conf_ctx_t *ctx, *http_ctx; | 2446 ngx_http_conf_ctx_t *ctx, *http_ctx; |
2447 ngx_http_listen_opt_t lsopt; | |
2313 ngx_http_core_srv_conf_t *cscf, **cscfp; | 2448 ngx_http_core_srv_conf_t *cscf, **cscfp; |
2314 ngx_http_core_main_conf_t *cmcf; | 2449 ngx_http_core_main_conf_t *cmcf; |
2315 | 2450 |
2316 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); | 2451 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); |
2317 if (ctx == NULL) { | 2452 if (ctx == NULL) { |
2385 cf->cmd_type = NGX_HTTP_SRV_CONF; | 2520 cf->cmd_type = NGX_HTTP_SRV_CONF; |
2386 | 2521 |
2387 rv = ngx_conf_parse(cf, NULL); | 2522 rv = ngx_conf_parse(cf, NULL); |
2388 | 2523 |
2389 *cf = pcf; | 2524 *cf = pcf; |
2525 | |
2526 if (rv == NGX_CONF_OK && !cscf->listen) { | |
2527 ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t)); | |
2528 | |
2529 sin = &lsopt.u.sockaddr_in; | |
2530 | |
2531 sin->sin_family = AF_INET; | |
2532 #if (NGX_WIN32) | |
2533 sin->sin_port = htons(80); | |
2534 #else | |
2535 sin->sin_port = htons((getuid() == 0) ? 80 : 8000); | |
2536 #endif | |
2537 sin->sin_addr.s_addr = INADDR_ANY; | |
2538 | |
2539 lsopt.socklen = sizeof(struct sockaddr_in); | |
2540 | |
2541 lsopt.backlog = NGX_LISTEN_BACKLOG; | |
2542 lsopt.rcvbuf = -1; | |
2543 lsopt.sndbuf = -1; | |
2544 #if (NGX_HAVE_SETFIB) | |
2545 lsopt.setfib = -1; | |
2546 #endif | |
2547 lsopt.wildcard = 1; | |
2548 | |
2549 (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr, | |
2550 NGX_SOCKADDR_STRLEN, 1); | |
2551 | |
2552 if (ngx_http_add_listen(cf, cscf, &lsopt) != NGX_OK) { | |
2553 return NGX_CONF_ERROR; | |
2554 } | |
2555 } | |
2390 | 2556 |
2391 return rv; | 2557 return rv; |
2392 } | 2558 } |
2393 | 2559 |
2394 | 2560 |
2589 static ngx_int_t | 2755 static ngx_int_t |
2590 ngx_http_core_regex_location(ngx_conf_t *cf, ngx_http_core_loc_conf_t *clcf, | 2756 ngx_http_core_regex_location(ngx_conf_t *cf, ngx_http_core_loc_conf_t *clcf, |
2591 ngx_str_t *regex, ngx_uint_t caseless) | 2757 ngx_str_t *regex, ngx_uint_t caseless) |
2592 { | 2758 { |
2593 #if (NGX_PCRE) | 2759 #if (NGX_PCRE) |
2594 ngx_str_t err; | 2760 ngx_regex_compile_t rc; |
2595 u_char errstr[NGX_MAX_CONF_ERRSTR]; | 2761 u_char errstr[NGX_MAX_CONF_ERRSTR]; |
2596 | 2762 |
2597 err.len = NGX_MAX_CONF_ERRSTR; | 2763 ngx_memzero(&rc, sizeof(ngx_regex_compile_t)); |
2598 err.data = errstr; | 2764 |
2765 rc.pattern = *regex; | |
2766 rc.err.len = NGX_MAX_CONF_ERRSTR; | |
2767 rc.err.data = errstr; | |
2599 | 2768 |
2600 #if (NGX_HAVE_CASELESS_FILESYSTEM) | 2769 #if (NGX_HAVE_CASELESS_FILESYSTEM) |
2601 caseless = 1; | 2770 rc.options = NGX_REGEX_CASELESS; |
2771 #else | |
2772 rc.options = caseless; | |
2602 #endif | 2773 #endif |
2603 | 2774 |
2604 clcf->regex = ngx_regex_compile(regex, caseless ? NGX_REGEX_CASELESS: 0, | 2775 clcf->regex = ngx_http_regex_compile(cf, &rc); |
2605 cf->pool, &err); | |
2606 | |
2607 if (clcf->regex == NULL) { | 2776 if (clcf->regex == NULL) { |
2608 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); | |
2609 return NGX_ERROR; | 2777 return NGX_ERROR; |
2610 } | 2778 } |
2611 | 2779 |
2612 clcf->name = *regex; | 2780 clcf->name = *regex; |
2613 clcf->captures = (ngx_regex_capture_count(clcf->regex) > 0); | |
2614 | 2781 |
2615 return NGX_OK; | 2782 return NGX_OK; |
2616 | 2783 |
2617 #else | 2784 #else |
2618 | 2785 |
2626 | 2793 |
2627 | 2794 |
2628 static char * | 2795 static char * |
2629 ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 2796 ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
2630 { | 2797 { |
2631 ngx_http_core_loc_conf_t *lcf = conf; | 2798 ngx_http_core_loc_conf_t *clcf = conf; |
2632 | 2799 |
2633 char *rv; | 2800 char *rv; |
2634 ngx_conf_t save; | 2801 ngx_conf_t save; |
2635 | 2802 |
2636 if (lcf->types == NULL) { | 2803 if (clcf->types == NULL) { |
2637 lcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t)); | 2804 clcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t)); |
2638 if (lcf->types == NULL) { | 2805 if (clcf->types == NULL) { |
2639 return NGX_CONF_ERROR; | 2806 return NGX_CONF_ERROR; |
2640 } | 2807 } |
2641 } | 2808 } |
2642 | 2809 |
2643 save = *cf; | 2810 save = *cf; |
2653 | 2820 |
2654 | 2821 |
2655 static char * | 2822 static char * |
2656 ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) | 2823 ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) |
2657 { | 2824 { |
2658 ngx_http_core_loc_conf_t *lcf = conf; | 2825 ngx_http_core_loc_conf_t *clcf = conf; |
2659 | 2826 |
2660 ngx_str_t *value, *content_type, *old, file; | 2827 ngx_str_t *value, *content_type, *old, file; |
2661 ngx_uint_t i, n, hash; | 2828 ngx_uint_t i, n, hash; |
2662 ngx_hash_key_t *type; | 2829 ngx_hash_key_t *type; |
2663 | 2830 |
2684 | 2851 |
2685 for (i = 1; i < cf->args->nelts; i++) { | 2852 for (i = 1; i < cf->args->nelts; i++) { |
2686 | 2853 |
2687 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len); | 2854 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len); |
2688 | 2855 |
2689 type = lcf->types->elts; | 2856 type = clcf->types->elts; |
2690 for (n = 0; n < lcf->types->nelts; n++) { | 2857 for (n = 0; n < clcf->types->nelts; n++) { |
2691 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) { | 2858 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) { |
2692 old = type[n].value; | 2859 old = type[n].value; |
2693 type[n].value = content_type; | 2860 type[n].value = content_type; |
2694 | 2861 |
2695 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | 2862 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
2700 continue; | 2867 continue; |
2701 } | 2868 } |
2702 } | 2869 } |
2703 | 2870 |
2704 | 2871 |
2705 type = ngx_array_push(lcf->types); | 2872 type = ngx_array_push(clcf->types); |
2706 if (type == NULL) { | 2873 if (type == NULL) { |
2707 return NGX_CONF_ERROR; | 2874 return NGX_CONF_ERROR; |
2708 } | 2875 } |
2709 | 2876 |
2710 type->key = value[i]; | 2877 type->key = value[i]; |
2776 } | 2943 } |
2777 | 2944 |
2778 cmcf->variables_hash_bucket_size = | 2945 cmcf->variables_hash_bucket_size = |
2779 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size); | 2946 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size); |
2780 | 2947 |
2948 if (cmcf->ncaptures) { | |
2949 cmcf->ncaptures = (cmcf->ncaptures + 1) * 3; | |
2950 } | |
2951 | |
2781 return NGX_CONF_OK; | 2952 return NGX_CONF_OK; |
2782 } | 2953 } |
2783 | 2954 |
2784 | 2955 |
2785 static void * | 2956 static void * |
2795 /* | 2966 /* |
2796 * set by ngx_pcalloc(): | 2967 * set by ngx_pcalloc(): |
2797 * | 2968 * |
2798 * conf->client_large_buffers.num = 0; | 2969 * conf->client_large_buffers.num = 0; |
2799 */ | 2970 */ |
2800 | |
2801 if (ngx_array_init(&cscf->listen, cf->temp_pool, 4, | |
2802 sizeof(ngx_http_listen_t)) | |
2803 != NGX_OK) | |
2804 { | |
2805 return NULL; | |
2806 } | |
2807 | 2971 |
2808 if (ngx_array_init(&cscf->server_names, cf->temp_pool, 4, | 2972 if (ngx_array_init(&cscf->server_names, cf->temp_pool, 4, |
2809 sizeof(ngx_http_server_name_t)) | 2973 sizeof(ngx_http_server_name_t)) |
2810 != NGX_OK) | 2974 != NGX_OK) |
2811 { | 2975 { |
2828 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) | 2992 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) |
2829 { | 2993 { |
2830 ngx_http_core_srv_conf_t *prev = parent; | 2994 ngx_http_core_srv_conf_t *prev = parent; |
2831 ngx_http_core_srv_conf_t *conf = child; | 2995 ngx_http_core_srv_conf_t *conf = child; |
2832 | 2996 |
2833 ngx_http_listen_t *ls; | 2997 ngx_str_t name; |
2834 struct sockaddr_in *sin; | |
2835 ngx_http_server_name_t *sn; | 2998 ngx_http_server_name_t *sn; |
2836 | 2999 |
2837 /* TODO: it does not merge, it inits only */ | 3000 /* TODO: it does not merge, it inits only */ |
2838 | |
2839 if (conf->listen.nelts == 0) { | |
2840 ls = ngx_array_push(&conf->listen); | |
2841 if (ls == NULL) { | |
2842 return NGX_CONF_ERROR; | |
2843 } | |
2844 | |
2845 ngx_memzero(ls, sizeof(ngx_http_listen_t)); | |
2846 | |
2847 sin = (struct sockaddr_in *) &ls->sockaddr; | |
2848 | |
2849 sin->sin_family = AF_INET; | |
2850 #if (NGX_WIN32) | |
2851 sin->sin_port = htons(80); | |
2852 #else | |
2853 sin->sin_port = htons((getuid() == 0) ? 80 : 8000); | |
2854 #endif | |
2855 sin->sin_addr.s_addr = INADDR_ANY; | |
2856 | |
2857 ls->socklen = sizeof(struct sockaddr_in); | |
2858 | |
2859 ls->conf.backlog = NGX_LISTEN_BACKLOG; | |
2860 ls->conf.rcvbuf = -1; | |
2861 ls->conf.sndbuf = -1; | |
2862 ls->conf.wildcard = 1; | |
2863 | |
2864 (void) ngx_sock_ntop((struct sockaddr *) &ls->sockaddr, ls->conf.addr, | |
2865 NGX_SOCKADDR_STRLEN, 1); | |
2866 } | |
2867 | |
2868 if (conf->server_name.data == NULL) { | |
2869 conf->server_name = cf->cycle->hostname; | |
2870 | |
2871 sn = ngx_array_push(&conf->server_names); | |
2872 if (sn == NULL) { | |
2873 return NGX_CONF_ERROR; | |
2874 } | |
2875 | |
2876 #if (NGX_PCRE) | |
2877 sn->regex = NULL; | |
2878 sn->captures = 0; | |
2879 #endif | |
2880 sn->core_srv_conf = conf; | |
2881 sn->name.len = conf->server_name.len; | |
2882 sn->name.data = conf->server_name.data; | |
2883 } | |
2884 | 3001 |
2885 ngx_conf_merge_size_value(conf->connection_pool_size, | 3002 ngx_conf_merge_size_value(conf->connection_pool_size, |
2886 prev->connection_pool_size, 256); | 3003 prev->connection_pool_size, 256); |
2887 ngx_conf_merge_size_value(conf->request_pool_size, | 3004 ngx_conf_merge_size_value(conf->request_pool_size, |
2888 prev->request_pool_size, 4096); | 3005 prev->request_pool_size, 4096); |
2890 prev->client_header_timeout, 60000); | 3007 prev->client_header_timeout, 60000); |
2891 ngx_conf_merge_size_value(conf->client_header_buffer_size, | 3008 ngx_conf_merge_size_value(conf->client_header_buffer_size, |
2892 prev->client_header_buffer_size, 1024); | 3009 prev->client_header_buffer_size, 1024); |
2893 ngx_conf_merge_bufs_value(conf->large_client_header_buffers, | 3010 ngx_conf_merge_bufs_value(conf->large_client_header_buffers, |
2894 prev->large_client_header_buffers, | 3011 prev->large_client_header_buffers, |
2895 4, ngx_pagesize); | 3012 4, 8192); |
2896 | 3013 |
2897 if (conf->large_client_header_buffers.size < conf->connection_pool_size) { | 3014 if (conf->large_client_header_buffers.size < conf->connection_pool_size) { |
2898 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3015 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2899 "the \"large_client_header_buffers\" size must be " | 3016 "the \"large_client_header_buffers\" size must be " |
2900 "equal to or bigger than \"connection_pool_size\""); | 3017 "equal to or bigger than \"connection_pool_size\""); |
2907 ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1); | 3024 ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1); |
2908 | 3025 |
2909 ngx_conf_merge_value(conf->underscores_in_headers, | 3026 ngx_conf_merge_value(conf->underscores_in_headers, |
2910 prev->underscores_in_headers, 0); | 3027 prev->underscores_in_headers, 0); |
2911 | 3028 |
3029 if (conf->server_names.nelts == 0) { | |
3030 /* the array has 4 empty preallocated elements, so push can not fail */ | |
3031 sn = ngx_array_push(&conf->server_names); | |
3032 #if (NGX_PCRE) | |
3033 sn->regex = NULL; | |
3034 #endif | |
3035 sn->server = conf; | |
3036 ngx_str_set(&sn->name, ""); | |
3037 } | |
3038 | |
3039 sn = conf->server_names.elts; | |
3040 name = sn[0].name; | |
3041 | |
3042 #if (NGX_PCRE) | |
3043 if (sn->regex) { | |
3044 name.len++; | |
3045 name.data--; | |
3046 } else | |
3047 #endif | |
3048 | |
3049 if (name.data[0] == '.') { | |
3050 name.len--; | |
3051 name.data++; | |
3052 } | |
3053 | |
3054 conf->server_name.len = name.len; | |
3055 conf->server_name.data = ngx_pstrdup(cf->pool, &name); | |
3056 if (conf->server_name.data == NULL) { | |
3057 return NGX_CONF_ERROR; | |
3058 } | |
3059 | |
2912 return NGX_CONF_OK; | 3060 return NGX_CONF_OK; |
2913 } | 3061 } |
2914 | 3062 |
2915 | 3063 |
2916 static void * | 3064 static void * |
2917 ngx_http_core_create_loc_conf(ngx_conf_t *cf) | 3065 ngx_http_core_create_loc_conf(ngx_conf_t *cf) |
2918 { | 3066 { |
2919 ngx_http_core_loc_conf_t *lcf; | 3067 ngx_http_core_loc_conf_t *clcf; |
2920 | 3068 |
2921 lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)); | 3069 clcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)); |
2922 if (lcf == NULL) { | 3070 if (clcf == NULL) { |
2923 return NULL; | 3071 return NULL; |
2924 } | 3072 } |
2925 | 3073 |
2926 /* | 3074 /* |
2927 * set by ngx_pcalloc(): | 3075 * set by ngx_pcalloc(): |
2928 * | 3076 * |
2929 * lcf->root = { 0, NULL }; | 3077 * clcf->root = { 0, NULL }; |
2930 * lcf->limit_except = 0; | 3078 * clcf->limit_except = 0; |
2931 * lcf->post_action = { 0, NULL }; | 3079 * clcf->post_action = { 0, NULL }; |
2932 * lcf->types = NULL; | 3080 * clcf->types = NULL; |
2933 * lcf->default_type = { 0, NULL }; | 3081 * clcf->default_type = { 0, NULL }; |
2934 * lcf->error_log = NULL; | 3082 * clcf->error_log = NULL; |
2935 * lcf->error_pages = NULL; | 3083 * clcf->error_pages = NULL; |
2936 * lcf->try_files = NULL; | 3084 * clcf->try_files = NULL; |
2937 * lcf->client_body_path = NULL; | 3085 * clcf->client_body_path = NULL; |
2938 * lcf->regex = NULL; | 3086 * clcf->regex = NULL; |
2939 * lcf->exact_match = 0; | 3087 * clcf->exact_match = 0; |
2940 * lcf->auto_redirect = 0; | 3088 * clcf->auto_redirect = 0; |
2941 * lcf->alias = 0; | 3089 * clcf->alias = 0; |
2942 * lcf->gzip_proxied = 0; | 3090 * clcf->gzip_proxied = 0; |
2943 */ | 3091 */ |
2944 | 3092 |
2945 lcf->client_max_body_size = NGX_CONF_UNSET; | 3093 clcf->client_max_body_size = NGX_CONF_UNSET; |
2946 lcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE; | 3094 clcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE; |
2947 lcf->client_body_timeout = NGX_CONF_UNSET_MSEC; | 3095 clcf->client_body_timeout = NGX_CONF_UNSET_MSEC; |
2948 lcf->satisfy = NGX_CONF_UNSET_UINT; | 3096 clcf->keepalive_disable = NGX_CONF_UNSET_UINT; |
2949 lcf->if_modified_since = NGX_CONF_UNSET_UINT; | 3097 clcf->satisfy = NGX_CONF_UNSET_UINT; |
2950 lcf->client_body_in_file_only = NGX_CONF_UNSET_UINT; | 3098 clcf->if_modified_since = NGX_CONF_UNSET_UINT; |
2951 lcf->client_body_in_single_buffer = NGX_CONF_UNSET; | 3099 clcf->client_body_in_file_only = NGX_CONF_UNSET_UINT; |
2952 lcf->internal = NGX_CONF_UNSET; | 3100 clcf->client_body_in_single_buffer = NGX_CONF_UNSET; |
2953 lcf->sendfile = NGX_CONF_UNSET; | 3101 clcf->internal = NGX_CONF_UNSET; |
2954 lcf->sendfile_max_chunk = NGX_CONF_UNSET_SIZE; | 3102 clcf->sendfile = NGX_CONF_UNSET; |
3103 clcf->sendfile_max_chunk = NGX_CONF_UNSET_SIZE; | |
2955 #if (NGX_HAVE_FILE_AIO) | 3104 #if (NGX_HAVE_FILE_AIO) |
2956 lcf->aio = NGX_CONF_UNSET; | 3105 clcf->aio = NGX_CONF_UNSET; |
2957 #endif | 3106 #endif |
2958 lcf->directio = NGX_CONF_UNSET; | 3107 clcf->read_ahead = NGX_CONF_UNSET_SIZE; |
2959 lcf->directio_alignment = NGX_CONF_UNSET; | 3108 clcf->directio = NGX_CONF_UNSET; |
2960 lcf->tcp_nopush = NGX_CONF_UNSET; | 3109 clcf->directio_alignment = NGX_CONF_UNSET; |
2961 lcf->tcp_nodelay = NGX_CONF_UNSET; | 3110 clcf->tcp_nopush = NGX_CONF_UNSET; |
2962 lcf->send_timeout = NGX_CONF_UNSET_MSEC; | 3111 clcf->tcp_nodelay = NGX_CONF_UNSET; |
2963 lcf->send_lowat = NGX_CONF_UNSET_SIZE; | 3112 clcf->send_timeout = NGX_CONF_UNSET_MSEC; |
2964 lcf->postpone_output = NGX_CONF_UNSET_SIZE; | 3113 clcf->send_lowat = NGX_CONF_UNSET_SIZE; |
2965 lcf->limit_rate = NGX_CONF_UNSET_SIZE; | 3114 clcf->postpone_output = NGX_CONF_UNSET_SIZE; |
2966 lcf->limit_rate_after = NGX_CONF_UNSET_SIZE; | 3115 clcf->limit_rate = NGX_CONF_UNSET_SIZE; |
2967 lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC; | 3116 clcf->limit_rate_after = NGX_CONF_UNSET_SIZE; |
2968 lcf->keepalive_header = NGX_CONF_UNSET; | 3117 clcf->keepalive_timeout = NGX_CONF_UNSET_MSEC; |
2969 lcf->keepalive_requests = NGX_CONF_UNSET_UINT; | 3118 clcf->keepalive_header = NGX_CONF_UNSET; |
2970 lcf->lingering_time = NGX_CONF_UNSET_MSEC; | 3119 clcf->keepalive_requests = NGX_CONF_UNSET_UINT; |
2971 lcf->lingering_timeout = NGX_CONF_UNSET_MSEC; | 3120 clcf->lingering_time = NGX_CONF_UNSET_MSEC; |
2972 lcf->resolver_timeout = NGX_CONF_UNSET_MSEC; | 3121 clcf->lingering_timeout = NGX_CONF_UNSET_MSEC; |
2973 lcf->reset_timedout_connection = NGX_CONF_UNSET; | 3122 clcf->resolver_timeout = NGX_CONF_UNSET_MSEC; |
2974 lcf->server_name_in_redirect = NGX_CONF_UNSET; | 3123 clcf->reset_timedout_connection = NGX_CONF_UNSET; |
2975 lcf->port_in_redirect = NGX_CONF_UNSET; | 3124 clcf->server_name_in_redirect = NGX_CONF_UNSET; |
2976 lcf->msie_padding = NGX_CONF_UNSET; | 3125 clcf->port_in_redirect = NGX_CONF_UNSET; |
2977 lcf->msie_refresh = NGX_CONF_UNSET; | 3126 clcf->msie_padding = NGX_CONF_UNSET; |
2978 lcf->log_not_found = NGX_CONF_UNSET; | 3127 clcf->msie_refresh = NGX_CONF_UNSET; |
2979 lcf->log_subrequest = NGX_CONF_UNSET; | 3128 clcf->log_not_found = NGX_CONF_UNSET; |
2980 lcf->recursive_error_pages = NGX_CONF_UNSET; | 3129 clcf->log_subrequest = NGX_CONF_UNSET; |
2981 lcf->server_tokens = NGX_CONF_UNSET; | 3130 clcf->recursive_error_pages = NGX_CONF_UNSET; |
2982 lcf->types_hash_max_size = NGX_CONF_UNSET_UINT; | 3131 clcf->server_tokens = NGX_CONF_UNSET; |
2983 lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT; | 3132 clcf->chunked_transfer_encoding = NGX_CONF_UNSET; |
2984 | 3133 clcf->types_hash_max_size = NGX_CONF_UNSET_UINT; |
2985 lcf->open_file_cache = NGX_CONF_UNSET_PTR; | 3134 clcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT; |
2986 lcf->open_file_cache_valid = NGX_CONF_UNSET; | 3135 |
2987 lcf->open_file_cache_min_uses = NGX_CONF_UNSET_UINT; | 3136 clcf->open_file_cache = NGX_CONF_UNSET_PTR; |
2988 lcf->open_file_cache_errors = NGX_CONF_UNSET; | 3137 clcf->open_file_cache_valid = NGX_CONF_UNSET; |
2989 lcf->open_file_cache_events = NGX_CONF_UNSET; | 3138 clcf->open_file_cache_min_uses = NGX_CONF_UNSET_UINT; |
3139 clcf->open_file_cache_errors = NGX_CONF_UNSET; | |
3140 clcf->open_file_cache_events = NGX_CONF_UNSET; | |
2990 | 3141 |
2991 #if (NGX_HTTP_GZIP) | 3142 #if (NGX_HTTP_GZIP) |
2992 lcf->gzip_vary = NGX_CONF_UNSET; | 3143 clcf->gzip_vary = NGX_CONF_UNSET; |
2993 lcf->gzip_http_version = NGX_CONF_UNSET_UINT; | 3144 clcf->gzip_http_version = NGX_CONF_UNSET_UINT; |
2994 #if (NGX_PCRE) | 3145 #if (NGX_PCRE) |
2995 lcf->gzip_disable = NGX_CONF_UNSET_PTR; | 3146 clcf->gzip_disable = NGX_CONF_UNSET_PTR; |
2996 lcf->gzip_disable_msie6 = 3; | 3147 #endif |
3148 clcf->gzip_disable_msie6 = 3; | |
3149 #if (NGX_HTTP_DEGRADATION) | |
3150 clcf->gzip_disable_degradation = 3; | |
2997 #endif | 3151 #endif |
2998 #endif | 3152 #endif |
2999 | 3153 |
3000 return lcf; | 3154 return clcf; |
3001 } | 3155 } |
3002 | 3156 |
3003 | 3157 |
3004 static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html"); | 3158 static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html"); |
3005 static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif"); | 3159 static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif"); |
3029 conf->root = prev->root; | 3183 conf->root = prev->root; |
3030 conf->root_lengths = prev->root_lengths; | 3184 conf->root_lengths = prev->root_lengths; |
3031 conf->root_values = prev->root_values; | 3185 conf->root_values = prev->root_values; |
3032 | 3186 |
3033 if (prev->root.data == NULL) { | 3187 if (prev->root.data == NULL) { |
3034 conf->root.len = sizeof("html") - 1; | 3188 ngx_str_set(&conf->root, "html"); |
3035 conf->root.data = (u_char *) "html"; | |
3036 | 3189 |
3037 if (ngx_conf_full_name(cf->cycle, &conf->root, 0) != NGX_OK) { | 3190 if (ngx_conf_full_name(cf->cycle, &conf->root, 0) != NGX_OK) { |
3038 return NGX_CONF_ERROR; | 3191 return NGX_CONF_ERROR; |
3039 } | 3192 } |
3040 } | 3193 } |
3139 prev->client_body_buffer_size, | 3292 prev->client_body_buffer_size, |
3140 (size_t) 2 * ngx_pagesize); | 3293 (size_t) 2 * ngx_pagesize); |
3141 ngx_conf_merge_msec_value(conf->client_body_timeout, | 3294 ngx_conf_merge_msec_value(conf->client_body_timeout, |
3142 prev->client_body_timeout, 60000); | 3295 prev->client_body_timeout, 60000); |
3143 | 3296 |
3297 ngx_conf_merge_uint_value(conf->keepalive_disable, prev->keepalive_disable, | |
3298 NGX_HTTP_KEEPALIVE_DISABLE_MSIE6 | |
3299 |NGX_HTTP_KEEPALIVE_DISABLE_SAFARI); | |
3144 ngx_conf_merge_uint_value(conf->satisfy, prev->satisfy, | 3300 ngx_conf_merge_uint_value(conf->satisfy, prev->satisfy, |
3145 NGX_HTTP_SATISFY_ALL); | 3301 NGX_HTTP_SATISFY_ALL); |
3146 ngx_conf_merge_uint_value(conf->if_modified_since, prev->if_modified_since, | 3302 ngx_conf_merge_uint_value(conf->if_modified_since, prev->if_modified_since, |
3147 NGX_HTTP_IMS_EXACT); | 3303 NGX_HTTP_IMS_EXACT); |
3148 ngx_conf_merge_uint_value(conf->client_body_in_file_only, | 3304 ngx_conf_merge_uint_value(conf->client_body_in_file_only, |
3154 ngx_conf_merge_size_value(conf->sendfile_max_chunk, | 3310 ngx_conf_merge_size_value(conf->sendfile_max_chunk, |
3155 prev->sendfile_max_chunk, 0); | 3311 prev->sendfile_max_chunk, 0); |
3156 #if (NGX_HAVE_FILE_AIO) | 3312 #if (NGX_HAVE_FILE_AIO) |
3157 ngx_conf_merge_value(conf->aio, prev->aio, 0); | 3313 ngx_conf_merge_value(conf->aio, prev->aio, 0); |
3158 #endif | 3314 #endif |
3315 ngx_conf_merge_size_value(conf->read_ahead, prev->read_ahead, 0); | |
3159 ngx_conf_merge_off_value(conf->directio, prev->directio, | 3316 ngx_conf_merge_off_value(conf->directio, prev->directio, |
3160 NGX_MAX_OFF_T_VALUE); | 3317 NGX_MAX_OFF_T_VALUE); |
3161 ngx_conf_merge_off_value(conf->directio_alignment, prev->directio_alignment, | 3318 ngx_conf_merge_off_value(conf->directio_alignment, prev->directio_alignment, |
3162 512); | 3319 512); |
3163 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0); | 3320 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0); |
3210 } | 3367 } |
3211 | 3368 |
3212 ngx_conf_merge_value(conf->reset_timedout_connection, | 3369 ngx_conf_merge_value(conf->reset_timedout_connection, |
3213 prev->reset_timedout_connection, 0); | 3370 prev->reset_timedout_connection, 0); |
3214 ngx_conf_merge_value(conf->server_name_in_redirect, | 3371 ngx_conf_merge_value(conf->server_name_in_redirect, |
3215 prev->server_name_in_redirect, 1); | 3372 prev->server_name_in_redirect, 0); |
3216 ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1); | 3373 ngx_conf_merge_value(conf->port_in_redirect, prev->port_in_redirect, 1); |
3217 ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1); | 3374 ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1); |
3218 ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0); | 3375 ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0); |
3219 ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1); | 3376 ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1); |
3220 ngx_conf_merge_value(conf->log_subrequest, prev->log_subrequest, 0); | 3377 ngx_conf_merge_value(conf->log_subrequest, prev->log_subrequest, 0); |
3221 ngx_conf_merge_value(conf->recursive_error_pages, | 3378 ngx_conf_merge_value(conf->recursive_error_pages, |
3222 prev->recursive_error_pages, 0); | 3379 prev->recursive_error_pages, 0); |
3223 ngx_conf_merge_value(conf->server_tokens, prev->server_tokens, 1); | 3380 ngx_conf_merge_value(conf->server_tokens, prev->server_tokens, 1); |
3381 ngx_conf_merge_value(conf->chunked_transfer_encoding, | |
3382 prev->chunked_transfer_encoding, 1); | |
3224 | 3383 |
3225 ngx_conf_merge_ptr_value(conf->open_file_cache, | 3384 ngx_conf_merge_ptr_value(conf->open_file_cache, |
3226 prev->open_file_cache, NULL); | 3385 prev->open_file_cache, NULL); |
3227 | 3386 |
3228 ngx_conf_merge_sec_value(conf->open_file_cache_valid, | 3387 ngx_conf_merge_sec_value(conf->open_file_cache_valid, |
3251 if (conf->gzip_disable_msie6 == 3) { | 3410 if (conf->gzip_disable_msie6 == 3) { |
3252 conf->gzip_disable_msie6 = | 3411 conf->gzip_disable_msie6 = |
3253 (prev->gzip_disable_msie6 == 3) ? 0 : prev->gzip_disable_msie6; | 3412 (prev->gzip_disable_msie6 == 3) ? 0 : prev->gzip_disable_msie6; |
3254 } | 3413 } |
3255 | 3414 |
3415 #if (NGX_HTTP_DEGRADATION) | |
3416 | |
3417 if (conf->gzip_disable_degradation == 3) { | |
3418 conf->gzip_disable_degradation = | |
3419 (prev->gzip_disable_degradation == 3) ? | |
3420 0 : prev->gzip_disable_degradation; | |
3421 } | |
3422 | |
3423 #endif | |
3256 #endif | 3424 #endif |
3257 | 3425 |
3258 return NGX_CONF_OK; | 3426 return NGX_CONF_OK; |
3259 } | 3427 } |
3260 | 3428 |
3261 | 3429 |
3262 static char * | 3430 static char * |
3263 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 3431 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
3264 { | 3432 { |
3265 ngx_http_core_srv_conf_t *scf = conf; | 3433 ngx_http_core_srv_conf_t *cscf = conf; |
3266 | 3434 |
3267 ngx_str_t *value, size; | 3435 ngx_str_t *value, size; |
3268 ngx_url_t u; | 3436 ngx_url_t u; |
3269 ngx_uint_t n; | 3437 ngx_uint_t n; |
3270 ngx_http_listen_t *ls; | 3438 ngx_http_listen_opt_t lsopt; |
3271 | 3439 |
3272 /* | 3440 cscf->listen = 1; |
3273 * TODO: check duplicate 'listen' directives, | |
3274 * add resolved name to server names ??? | |
3275 */ | |
3276 | 3441 |
3277 value = cf->args->elts; | 3442 value = cf->args->elts; |
3278 | 3443 |
3279 ngx_memzero(&u, sizeof(ngx_url_t)); | 3444 ngx_memzero(&u, sizeof(ngx_url_t)); |
3280 | 3445 |
3290 } | 3455 } |
3291 | 3456 |
3292 return NGX_CONF_ERROR; | 3457 return NGX_CONF_ERROR; |
3293 } | 3458 } |
3294 | 3459 |
3295 ls = ngx_array_push(&scf->listen); | 3460 ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t)); |
3296 if (ls == NULL) { | 3461 |
3297 return NGX_CONF_ERROR; | 3462 ngx_memcpy(&lsopt.u.sockaddr, u.sockaddr, u.socklen); |
3298 } | 3463 |
3299 | 3464 lsopt.socklen = u.socklen; |
3300 ngx_memzero(ls, sizeof(ngx_http_listen_t)); | 3465 lsopt.backlog = NGX_LISTEN_BACKLOG; |
3301 | 3466 lsopt.rcvbuf = -1; |
3302 ngx_memcpy(ls->sockaddr, u.sockaddr, u.socklen); | 3467 lsopt.sndbuf = -1; |
3303 | 3468 #if (NGX_HAVE_SETFIB) |
3304 ls->socklen = u.socklen; | 3469 lsopt.setfib = -1; |
3305 ls->file_name = cf->conf_file->file.name.data; | 3470 #endif |
3306 ls->line = cf->conf_file->line; | 3471 lsopt.wildcard = u.wildcard; |
3307 ls->conf.backlog = NGX_LISTEN_BACKLOG; | 3472 |
3308 ls->conf.rcvbuf = -1; | 3473 (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr, |
3309 ls->conf.sndbuf = -1; | |
3310 ls->conf.wildcard = u.wildcard; | |
3311 | |
3312 (void) ngx_sock_ntop((struct sockaddr *) &ls->sockaddr, ls->conf.addr, | |
3313 NGX_SOCKADDR_STRLEN, 1); | 3474 NGX_SOCKADDR_STRLEN, 1); |
3314 | 3475 |
3315 if (cf->args->nelts == 2) { | 3476 for (n = 2; n < cf->args->nelts; n++) { |
3316 return NGX_CONF_OK; | 3477 |
3317 } | 3478 if (ngx_strcmp(value[n].data, "default_server") == 0 |
3318 | 3479 || ngx_strcmp(value[n].data, "default") == 0) |
3319 if (ngx_strcmp(value[2].data, "default") == 0) { | 3480 { |
3320 ls->conf.default_server = 1; | 3481 lsopt.default_server = 1; |
3321 n = 3; | 3482 continue; |
3322 | |
3323 } else { | |
3324 n = 2; | |
3325 } | |
3326 | |
3327 for ( /* void */ ; n < cf->args->nelts; n++) { | |
3328 | |
3329 if (ls->conf.default_server == 0) { | |
3330 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
3331 "\"%V\" parameter can be specified for " | |
3332 "the default \"listen\" directive only", | |
3333 &value[n]); | |
3334 return NGX_CONF_ERROR; | |
3335 } | 3483 } |
3336 | 3484 |
3337 if (ngx_strcmp(value[n].data, "bind") == 0) { | 3485 if (ngx_strcmp(value[n].data, "bind") == 0) { |
3338 ls->conf.bind = 1; | 3486 lsopt.set = 1; |
3487 lsopt.bind = 1; | |
3339 continue; | 3488 continue; |
3340 } | 3489 } |
3341 | 3490 |
3491 #if (NGX_HAVE_SETFIB) | |
3492 if (ngx_strncmp(value[n].data, "setfib=", 7) == 0) { | |
3493 lsopt.setfib = ngx_atoi(value[n].data + 7, value[n].len - 7); | |
3494 | |
3495 if (lsopt.setfib == NGX_ERROR) { | |
3496 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
3497 "invalid setfib \"%V\"", &value[n]); | |
3498 return NGX_CONF_ERROR; | |
3499 } | |
3500 | |
3501 continue; | |
3502 } | |
3503 #endif | |
3342 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) { | 3504 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) { |
3343 ls->conf.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8); | 3505 lsopt.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8); |
3344 ls->conf.bind = 1; | 3506 lsopt.set = 1; |
3345 | 3507 lsopt.bind = 1; |
3346 if (ls->conf.backlog == NGX_ERROR || ls->conf.backlog == 0) { | 3508 |
3509 if (lsopt.backlog == NGX_ERROR || lsopt.backlog == 0) { | |
3347 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3510 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3348 "invalid backlog \"%V\"", &value[n]); | 3511 "invalid backlog \"%V\"", &value[n]); |
3349 return NGX_CONF_ERROR; | 3512 return NGX_CONF_ERROR; |
3350 } | 3513 } |
3351 | 3514 |
3354 | 3517 |
3355 if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) { | 3518 if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) { |
3356 size.len = value[n].len - 7; | 3519 size.len = value[n].len - 7; |
3357 size.data = value[n].data + 7; | 3520 size.data = value[n].data + 7; |
3358 | 3521 |
3359 ls->conf.rcvbuf = ngx_parse_size(&size); | 3522 lsopt.rcvbuf = ngx_parse_size(&size); |
3360 ls->conf.bind = 1; | 3523 lsopt.set = 1; |
3361 | 3524 lsopt.bind = 1; |
3362 if (ls->conf.rcvbuf == NGX_ERROR) { | 3525 |
3526 if (lsopt.rcvbuf == NGX_ERROR) { | |
3363 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3527 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3364 "invalid rcvbuf \"%V\"", &value[n]); | 3528 "invalid rcvbuf \"%V\"", &value[n]); |
3365 return NGX_CONF_ERROR; | 3529 return NGX_CONF_ERROR; |
3366 } | 3530 } |
3367 | 3531 |
3370 | 3534 |
3371 if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) { | 3535 if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) { |
3372 size.len = value[n].len - 7; | 3536 size.len = value[n].len - 7; |
3373 size.data = value[n].data + 7; | 3537 size.data = value[n].data + 7; |
3374 | 3538 |
3375 ls->conf.sndbuf = ngx_parse_size(&size); | 3539 lsopt.sndbuf = ngx_parse_size(&size); |
3376 ls->conf.bind = 1; | 3540 lsopt.set = 1; |
3377 | 3541 lsopt.bind = 1; |
3378 if (ls->conf.sndbuf == NGX_ERROR) { | 3542 |
3543 if (lsopt.sndbuf == NGX_ERROR) { | |
3379 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3544 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3380 "invalid sndbuf \"%V\"", &value[n]); | 3545 "invalid sndbuf \"%V\"", &value[n]); |
3381 return NGX_CONF_ERROR; | 3546 return NGX_CONF_ERROR; |
3382 } | 3547 } |
3383 | 3548 |
3384 continue; | 3549 continue; |
3385 } | 3550 } |
3386 | 3551 |
3387 if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) { | 3552 if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) { |
3388 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) | 3553 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) |
3389 ls->conf.accept_filter = (char *) &value[n].data[14]; | 3554 lsopt.accept_filter = (char *) &value[n].data[14]; |
3390 ls->conf.bind = 1; | 3555 lsopt.set = 1; |
3556 lsopt.bind = 1; | |
3391 #else | 3557 #else |
3392 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3558 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3393 "accept filters \"%V\" are not supported " | 3559 "accept filters \"%V\" are not supported " |
3394 "on this platform, ignored", | 3560 "on this platform, ignored", |
3395 &value[n]); | 3561 &value[n]); |
3397 continue; | 3563 continue; |
3398 } | 3564 } |
3399 | 3565 |
3400 if (ngx_strcmp(value[n].data, "deferred") == 0) { | 3566 if (ngx_strcmp(value[n].data, "deferred") == 0) { |
3401 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT) | 3567 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT) |
3402 ls->conf.deferred_accept = 1; | 3568 lsopt.deferred_accept = 1; |
3403 ls->conf.bind = 1; | 3569 lsopt.set = 1; |
3570 lsopt.bind = 1; | |
3404 #else | 3571 #else |
3405 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3572 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3406 "the deferred accept is not supported " | 3573 "the deferred accept is not supported " |
3407 "on this platform, ignored"); | 3574 "on this platform, ignored"); |
3408 #endif | 3575 #endif |
3411 | 3578 |
3412 if (ngx_strncmp(value[n].data, "ipv6only=o", 10) == 0) { | 3579 if (ngx_strncmp(value[n].data, "ipv6only=o", 10) == 0) { |
3413 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) | 3580 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) |
3414 struct sockaddr *sa; | 3581 struct sockaddr *sa; |
3415 | 3582 |
3416 sa = (struct sockaddr *) ls->sockaddr; | 3583 sa = &lsopt.u.sockaddr; |
3417 | 3584 |
3418 if (sa->sa_family == AF_INET6) { | 3585 if (sa->sa_family == AF_INET6) { |
3419 | 3586 |
3420 if (ngx_strcmp(&value[n].data[10], "n") == 0) { | 3587 if (ngx_strcmp(&value[n].data[10], "n") == 0) { |
3421 ls->conf.ipv6only = 1; | 3588 lsopt.ipv6only = 1; |
3422 | 3589 |
3423 } else if (ngx_strcmp(&value[n].data[10], "ff") == 0) { | 3590 } else if (ngx_strcmp(&value[n].data[10], "ff") == 0) { |
3424 ls->conf.ipv6only = 2; | 3591 lsopt.ipv6only = 2; |
3425 | 3592 |
3426 } else { | 3593 } else { |
3427 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3594 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3428 "invalid ipv6only flags \"%s\"", | 3595 "invalid ipv6only flags \"%s\"", |
3429 &value[n].data[9]); | 3596 &value[n].data[9]); |
3430 return NGX_CONF_ERROR; | 3597 return NGX_CONF_ERROR; |
3431 } | 3598 } |
3432 | 3599 |
3433 ls->conf.bind = 1; | 3600 lsopt.set = 1; |
3601 lsopt.bind = 1; | |
3434 | 3602 |
3435 } else { | 3603 } else { |
3436 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3604 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3437 "ipv6only is not supported " | 3605 "ipv6only is not supported " |
3438 "on addr \"%s\", ignored", | 3606 "on addr \"%s\", ignored", lsopt.addr); |
3439 ls->conf.addr); | |
3440 } | 3607 } |
3441 | 3608 |
3442 continue; | 3609 continue; |
3443 #else | 3610 #else |
3444 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3611 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3448 #endif | 3615 #endif |
3449 } | 3616 } |
3450 | 3617 |
3451 if (ngx_strcmp(value[n].data, "ssl") == 0) { | 3618 if (ngx_strcmp(value[n].data, "ssl") == 0) { |
3452 #if (NGX_HTTP_SSL) | 3619 #if (NGX_HTTP_SSL) |
3453 ls->conf.ssl = 1; | 3620 lsopt.ssl = 1; |
3454 continue; | 3621 continue; |
3455 #else | 3622 #else |
3456 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3623 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3457 "the \"ssl\" parameter requires " | 3624 "the \"ssl\" parameter requires " |
3458 "ngx_http_ssl_module"); | 3625 "ngx_http_ssl_module"); |
3463 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3630 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3464 "the invalid \"%V\" parameter", &value[n]); | 3631 "the invalid \"%V\" parameter", &value[n]); |
3465 return NGX_CONF_ERROR; | 3632 return NGX_CONF_ERROR; |
3466 } | 3633 } |
3467 | 3634 |
3468 return NGX_CONF_OK; | 3635 if (ngx_http_add_listen(cf, cscf, &lsopt) == NGX_OK) { |
3636 return NGX_CONF_OK; | |
3637 } | |
3638 | |
3639 return NGX_CONF_ERROR; | |
3469 } | 3640 } |
3470 | 3641 |
3471 | 3642 |
3472 static char * | 3643 static char * |
3473 ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 3644 ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
3474 { | 3645 { |
3475 ngx_http_core_srv_conf_t *cscf = conf; | 3646 ngx_http_core_srv_conf_t *cscf = conf; |
3476 | 3647 |
3477 u_char ch; | 3648 u_char ch; |
3478 ngx_str_t *value, name; | 3649 ngx_str_t *value; |
3479 ngx_uint_t i; | 3650 ngx_uint_t i; |
3480 ngx_http_server_name_t *sn; | 3651 ngx_http_server_name_t *sn; |
3481 | 3652 |
3482 value = cf->args->elts; | 3653 value = cf->args->elts; |
3483 | |
3484 ch = value[1].data[0]; | |
3485 | |
3486 if (cscf->server_name.data == NULL) { | |
3487 if (value[1].len) { | |
3488 name = value[1]; | |
3489 | |
3490 if (ch == '.') { | |
3491 name.len--; | |
3492 name.data++; | |
3493 } | |
3494 | |
3495 cscf->server_name.len = name.len; | |
3496 cscf->server_name.data = ngx_pstrdup(cf->pool, &name); | |
3497 if (cscf->server_name.data == NULL) { | |
3498 return NGX_CONF_ERROR; | |
3499 } | |
3500 | |
3501 } else { | |
3502 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
3503 "the first server name must not be empty"); | |
3504 return NGX_CONF_ERROR; | |
3505 } | |
3506 } | |
3507 | 3654 |
3508 for (i = 1; i < cf->args->nelts; i++) { | 3655 for (i = 1; i < cf->args->nelts; i++) { |
3509 | 3656 |
3510 ch = value[i].data[0]; | 3657 ch = value[i].data[0]; |
3511 | 3658 |
3535 return NGX_CONF_ERROR; | 3682 return NGX_CONF_ERROR; |
3536 } | 3683 } |
3537 | 3684 |
3538 #if (NGX_PCRE) | 3685 #if (NGX_PCRE) |
3539 sn->regex = NULL; | 3686 sn->regex = NULL; |
3540 sn->captures = 0; | |
3541 #endif | 3687 #endif |
3542 sn->core_srv_conf = cscf; | 3688 sn->server = cscf; |
3543 sn->name = value[i]; | 3689 |
3690 if (ngx_strcasecmp(value[i].data, (u_char *) "$hostname") == 0) { | |
3691 sn->name = cf->cycle->hostname; | |
3692 | |
3693 } else { | |
3694 sn->name = value[i]; | |
3695 } | |
3544 | 3696 |
3545 if (value[i].data[0] != '~') { | 3697 if (value[i].data[0] != '~') { |
3698 ngx_strlow(sn->name.data, sn->name.data, sn->name.len); | |
3546 continue; | 3699 continue; |
3547 } | 3700 } |
3548 | 3701 |
3549 #if (NGX_PCRE) | 3702 #if (NGX_PCRE) |
3550 { | 3703 { |
3551 ngx_str_t err; | 3704 u_char *p; |
3552 u_char errstr[NGX_MAX_CONF_ERRSTR]; | 3705 ngx_regex_compile_t rc; |
3706 u_char errstr[NGX_MAX_CONF_ERRSTR]; | |
3553 | 3707 |
3554 if (value[i].len == 1) { | 3708 if (value[i].len == 1) { |
3555 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3709 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3556 "empty regex in server name \"%V\"", &value[i]); | 3710 "empty regex in server name \"%V\"", &value[i]); |
3557 return NGX_CONF_ERROR; | 3711 return NGX_CONF_ERROR; |
3558 } | 3712 } |
3559 | 3713 |
3560 err.len = NGX_MAX_CONF_ERRSTR; | |
3561 err.data = errstr; | |
3562 | |
3563 value[i].len--; | 3714 value[i].len--; |
3564 value[i].data++; | 3715 value[i].data++; |
3565 | 3716 |
3566 sn->regex = ngx_regex_compile(&value[i], 0, cf->pool, &err); | 3717 ngx_memzero(&rc, sizeof(ngx_regex_compile_t)); |
3567 | 3718 |
3719 rc.pattern = value[i]; | |
3720 rc.err.len = NGX_MAX_CONF_ERRSTR; | |
3721 rc.err.data = errstr; | |
3722 | |
3723 for (p = value[i].data; p < value[i].data + value[i].len; p++) { | |
3724 if (*p >= 'A' && *p <= 'Z') { | |
3725 rc.options = NGX_REGEX_CASELESS; | |
3726 break; | |
3727 } | |
3728 } | |
3729 | |
3730 sn->regex = ngx_http_regex_compile(cf, &rc); | |
3568 if (sn->regex == NULL) { | 3731 if (sn->regex == NULL) { |
3569 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); | |
3570 return NGX_CONF_ERROR; | 3732 return NGX_CONF_ERROR; |
3571 } | 3733 } |
3572 | 3734 |
3573 sn->captures = (ngx_regex_capture_count(sn->regex) > 0); | |
3574 sn->name = value[i]; | 3735 sn->name = value[i]; |
3736 cscf->captures = (rc.captures > 0); | |
3575 } | 3737 } |
3576 #else | 3738 #else |
3577 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3739 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3578 "the using of the regex \"%V\" " | 3740 "the using of the regex \"%V\" " |
3579 "requires PCRE library", &value[i]); | 3741 "requires PCRE library", &value[i]); |
3587 | 3749 |
3588 | 3750 |
3589 static char * | 3751 static char * |
3590 ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 3752 ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
3591 { | 3753 { |
3592 ngx_http_core_loc_conf_t *lcf = conf; | 3754 ngx_http_core_loc_conf_t *clcf = conf; |
3593 | 3755 |
3594 ngx_str_t *value; | 3756 ngx_str_t *value; |
3595 ngx_uint_t alias, n; | 3757 ngx_int_t alias; |
3758 ngx_uint_t n; | |
3596 ngx_http_script_compile_t sc; | 3759 ngx_http_script_compile_t sc; |
3597 | 3760 |
3598 alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0; | 3761 alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0; |
3599 | 3762 |
3600 if (lcf->root.data) { | 3763 if (clcf->root.data) { |
3601 | 3764 |
3602 /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */ | 3765 if ((clcf->alias != 0) == alias) { |
3603 | |
3604 if ((ngx_uint_t) lcf->alias == alias) { | |
3605 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3766 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3606 "\"%V\" directive is duplicate", | 3767 "\"%V\" directive is duplicate", |
3607 &cmd->name); | 3768 &cmd->name); |
3608 } else { | 3769 } else { |
3609 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3770 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3610 "\"%V\" directive is duplicate, " | 3771 "\"%V\" directive is duplicate, " |
3611 "\"%s\" directive is specified before", | 3772 "\"%s\" directive is specified before", |
3612 &cmd->name, lcf->alias ? "alias" : "root"); | 3773 &cmd->name, clcf->alias ? "alias" : "root"); |
3613 } | 3774 } |
3614 | 3775 |
3615 return NGX_CONF_ERROR; | 3776 return NGX_CONF_ERROR; |
3616 } | 3777 } |
3617 | 3778 |
3618 if (lcf->named && alias) { | 3779 if (clcf->named && alias) { |
3619 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3780 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3620 "the \"alias\" directive may not be used " | 3781 "the \"alias\" directive may not be used " |
3621 "inside named location"); | 3782 "inside named location"); |
3622 | 3783 |
3623 return NGX_CONF_ERROR; | 3784 return NGX_CONF_ERROR; |
3645 &cmd->name); | 3806 &cmd->name); |
3646 | 3807 |
3647 return NGX_CONF_ERROR; | 3808 return NGX_CONF_ERROR; |
3648 } | 3809 } |
3649 | 3810 |
3650 lcf->alias = alias; | 3811 clcf->alias = alias ? clcf->name.len : 0; |
3651 lcf->root = value[1]; | 3812 clcf->root = value[1]; |
3652 | 3813 |
3653 if (!alias && lcf->root.data[lcf->root.len - 1] == '/') { | 3814 if (!alias && clcf->root.data[clcf->root.len - 1] == '/') { |
3654 lcf->root.len--; | 3815 clcf->root.len--; |
3655 } | 3816 } |
3656 | 3817 |
3657 if (lcf->root.data[0] != '$') { | 3818 if (clcf->root.data[0] != '$') { |
3658 if (ngx_conf_full_name(cf->cycle, &lcf->root, 0) != NGX_OK) { | 3819 if (ngx_conf_full_name(cf->cycle, &clcf->root, 0) != NGX_OK) { |
3659 return NGX_CONF_ERROR; | 3820 return NGX_CONF_ERROR; |
3660 } | 3821 } |
3661 } | 3822 } |
3662 | 3823 |
3663 n = ngx_http_script_variables_count(&lcf->root); | 3824 n = ngx_http_script_variables_count(&clcf->root); |
3664 | 3825 |
3665 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | 3826 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); |
3827 sc.variables = n; | |
3828 | |
3829 #if (NGX_PCRE) | |
3830 if (alias && clcf->regex) { | |
3831 n = 1; | |
3832 } | |
3833 #endif | |
3666 | 3834 |
3667 if (n) { | 3835 if (n) { |
3668 sc.cf = cf; | 3836 sc.cf = cf; |
3669 sc.source = &lcf->root; | 3837 sc.source = &clcf->root; |
3670 sc.lengths = &lcf->root_lengths; | 3838 sc.lengths = &clcf->root_lengths; |
3671 sc.values = &lcf->root_values; | 3839 sc.values = &clcf->root_values; |
3672 sc.variables = n; | |
3673 sc.complete_lengths = 1; | 3840 sc.complete_lengths = 1; |
3674 sc.complete_values = 1; | 3841 sc.complete_values = 1; |
3675 | 3842 |
3676 if (ngx_http_script_compile(&sc) != NGX_OK) { | 3843 if (ngx_http_script_compile(&sc) != NGX_OK) { |
3677 return NGX_CONF_ERROR; | 3844 return NGX_CONF_ERROR; |
3678 } | 3845 } |
3679 } | 3846 } |
3680 | |
3681 #if (NGX_PCRE) | |
3682 | |
3683 if (alias && lcf->regex | |
3684 && (ngx_regex_capture_count(lcf->regex) <= 0 || sc.ncaptures == 0)) | |
3685 { | |
3686 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
3687 "the \"alias\" directive must use captures " | |
3688 "inside location given by regular expression"); | |
3689 | |
3690 return NGX_CONF_ERROR; | |
3691 } | |
3692 | |
3693 #endif | |
3694 | 3847 |
3695 return NGX_CONF_OK; | 3848 return NGX_CONF_OK; |
3696 } | 3849 } |
3697 | 3850 |
3698 | 3851 |
3708 { (u_char *) "OPTIONS", (uint32_t) ~NGX_HTTP_OPTIONS }, | 3861 { (u_char *) "OPTIONS", (uint32_t) ~NGX_HTTP_OPTIONS }, |
3709 { (u_char *) "PROPFIND" , (uint32_t) ~NGX_HTTP_PROPFIND }, | 3862 { (u_char *) "PROPFIND" , (uint32_t) ~NGX_HTTP_PROPFIND }, |
3710 { (u_char *) "PROPPATCH", (uint32_t) ~NGX_HTTP_PROPPATCH }, | 3863 { (u_char *) "PROPPATCH", (uint32_t) ~NGX_HTTP_PROPPATCH }, |
3711 { (u_char *) "LOCK", (uint32_t) ~NGX_HTTP_LOCK }, | 3864 { (u_char *) "LOCK", (uint32_t) ~NGX_HTTP_LOCK }, |
3712 { (u_char *) "UNLOCK", (uint32_t) ~NGX_HTTP_UNLOCK }, | 3865 { (u_char *) "UNLOCK", (uint32_t) ~NGX_HTTP_UNLOCK }, |
3866 { (u_char *) "PATCH", (uint32_t) ~NGX_HTTP_PATCH }, | |
3713 { NULL, 0 } | 3867 { NULL, 0 } |
3714 }; | 3868 }; |
3715 | 3869 |
3716 | 3870 |
3717 static char * | 3871 static char * |
3794 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index]; | 3948 clcf = ctx->loc_conf[ngx_http_core_module.ctx_index]; |
3795 pclcf->limit_except_loc_conf = ctx->loc_conf; | 3949 pclcf->limit_except_loc_conf = ctx->loc_conf; |
3796 clcf->loc_conf = ctx->loc_conf; | 3950 clcf->loc_conf = ctx->loc_conf; |
3797 clcf->name = pclcf->name; | 3951 clcf->name = pclcf->name; |
3798 clcf->noname = 1; | 3952 clcf->noname = 1; |
3953 clcf->lmt_excpt = 1; | |
3799 | 3954 |
3800 if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) { | 3955 if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) { |
3801 return NGX_CONF_ERROR; | 3956 return NGX_CONF_ERROR; |
3802 } | 3957 } |
3803 | 3958 |
3841 | 3996 |
3842 | 3997 |
3843 static char * | 3998 static char * |
3844 ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 3999 ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
3845 { | 4000 { |
3846 ngx_http_core_loc_conf_t *lcf = conf; | 4001 ngx_http_core_loc_conf_t *clcf = conf; |
3847 | 4002 |
3848 u_char *p; | 4003 u_char *p; |
3849 ngx_int_t overwrite; | 4004 ngx_int_t overwrite; |
3850 ngx_str_t *value, uri, args; | 4005 ngx_str_t *value, uri, args; |
3851 ngx_uint_t i, n; | 4006 ngx_uint_t i, n; |
3852 ngx_http_err_page_t *err; | 4007 ngx_http_err_page_t *err; |
3853 ngx_http_complex_value_t cv; | 4008 ngx_http_complex_value_t cv; |
3854 ngx_http_compile_complex_value_t ccv; | 4009 ngx_http_compile_complex_value_t ccv; |
3855 | 4010 |
3856 if (lcf->error_pages == NULL) { | 4011 if (clcf->error_pages == NULL) { |
3857 lcf->error_pages = ngx_array_create(cf->pool, 4, | 4012 clcf->error_pages = ngx_array_create(cf->pool, 4, |
3858 sizeof(ngx_http_err_page_t)); | 4013 sizeof(ngx_http_err_page_t)); |
3859 if (lcf->error_pages == NULL) { | 4014 if (clcf->error_pages == NULL) { |
3860 return NGX_CONF_ERROR; | 4015 return NGX_CONF_ERROR; |
3861 } | 4016 } |
3862 } | 4017 } |
3863 | 4018 |
3864 value = cf->args->elts; | 4019 value = cf->args->elts; |
3902 | 4057 |
3903 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { | 4058 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
3904 return NGX_CONF_ERROR; | 4059 return NGX_CONF_ERROR; |
3905 } | 4060 } |
3906 | 4061 |
3907 args.len = 0; | 4062 ngx_str_null(&args); |
3908 args.data = NULL; | |
3909 | 4063 |
3910 if (cv.lengths == NULL && uri.data[0] == '/') { | 4064 if (cv.lengths == NULL && uri.data[0] == '/') { |
3911 p = (u_char *) ngx_strchr(uri.data, '?'); | 4065 p = (u_char *) ngx_strchr(uri.data, '?'); |
3912 | 4066 |
3913 if (p) { | 4067 if (p) { |
3918 args.data = p; | 4072 args.data = p; |
3919 } | 4073 } |
3920 } | 4074 } |
3921 | 4075 |
3922 for (i = 1; i < cf->args->nelts - n; i++) { | 4076 for (i = 1; i < cf->args->nelts - n; i++) { |
3923 err = ngx_array_push(lcf->error_pages); | 4077 err = ngx_array_push(clcf->error_pages); |
3924 if (err == NULL) { | 4078 if (err == NULL) { |
3925 return NGX_CONF_ERROR; | 4079 return NGX_CONF_ERROR; |
3926 } | 4080 } |
3927 | 4081 |
3928 err->status = ngx_atoi(value[i].data, value[i].len); | 4082 err->status = ngx_atoi(value[i].data, value[i].len); |
3931 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 4085 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3932 "invalid value \"%V\"", &value[i]); | 4086 "invalid value \"%V\"", &value[i]); |
3933 return NGX_CONF_ERROR; | 4087 return NGX_CONF_ERROR; |
3934 } | 4088 } |
3935 | 4089 |
3936 if (err->status < 400 || err->status > 599) { | 4090 if (err->status < 300 || err->status > 599) { |
3937 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 4091 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3938 "value \"%V\" must be between 400 and 599", | 4092 "value \"%V\" must be between 300 and 599", |
3939 &value[i]); | 4093 &value[i]); |
3940 return NGX_CONF_ERROR; | 4094 return NGX_CONF_ERROR; |
3941 } | 4095 } |
3942 | 4096 |
3943 if (overwrite >= 0) { | 4097 err->overwrite = overwrite; |
3944 err->overwrite = overwrite; | 4098 |
3945 | 4099 if (overwrite == -1) { |
3946 } else { | |
3947 switch (err->status) { | 4100 switch (err->status) { |
3948 case NGX_HTTP_TO_HTTPS: | 4101 case NGX_HTTP_TO_HTTPS: |
3949 case NGX_HTTPS_CERT_ERROR: | 4102 case NGX_HTTPS_CERT_ERROR: |
3950 case NGX_HTTPS_NO_CERT: | 4103 case NGX_HTTPS_NO_CERT: |
3951 err->overwrite = NGX_HTTP_BAD_REQUEST; | 4104 err->overwrite = NGX_HTTP_BAD_REQUEST; |
3952 break; | |
3953 | |
3954 default: | 4105 default: |
3955 err->overwrite = err->status; | |
3956 break; | 4106 break; |
3957 } | 4107 } |
3958 } | 4108 } |
3959 | 4109 |
3960 err->value = cv; | 4110 err->value = cv; |
4046 | 4196 |
4047 | 4197 |
4048 static char * | 4198 static char * |
4049 ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 4199 ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
4050 { | 4200 { |
4051 ngx_http_core_loc_conf_t *lcf = conf; | 4201 ngx_http_core_loc_conf_t *clcf = conf; |
4052 | 4202 |
4053 time_t inactive; | 4203 time_t inactive; |
4054 ngx_str_t *value, s; | 4204 ngx_str_t *value, s; |
4055 ngx_int_t max; | 4205 ngx_int_t max; |
4056 ngx_uint_t i; | 4206 ngx_uint_t i; |
4057 | 4207 |
4058 if (lcf->open_file_cache != NGX_CONF_UNSET_PTR) { | 4208 if (clcf->open_file_cache != NGX_CONF_UNSET_PTR) { |
4059 return "is duplicate"; | 4209 return "is duplicate"; |
4060 } | 4210 } |
4061 | 4211 |
4062 value = cf->args->elts; | 4212 value = cf->args->elts; |
4063 | 4213 |
4089 continue; | 4239 continue; |
4090 } | 4240 } |
4091 | 4241 |
4092 if (ngx_strcmp(value[i].data, "off") == 0) { | 4242 if (ngx_strcmp(value[i].data, "off") == 0) { |
4093 | 4243 |
4094 lcf->open_file_cache = NULL; | 4244 clcf->open_file_cache = NULL; |
4095 | 4245 |
4096 continue; | 4246 continue; |
4097 } | 4247 } |
4098 | 4248 |
4099 failed: | 4249 failed: |
4102 "invalid \"open_file_cache\" parameter \"%V\"", | 4252 "invalid \"open_file_cache\" parameter \"%V\"", |
4103 &value[i]); | 4253 &value[i]); |
4104 return NGX_CONF_ERROR; | 4254 return NGX_CONF_ERROR; |
4105 } | 4255 } |
4106 | 4256 |
4107 if (lcf->open_file_cache == NULL) { | 4257 if (clcf->open_file_cache == NULL) { |
4108 return NGX_CONF_OK; | 4258 return NGX_CONF_OK; |
4109 } | 4259 } |
4110 | 4260 |
4111 if (max == 0) { | 4261 if (max == 0) { |
4112 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 4262 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
4113 "\"open_file_cache\" must have \"max\" parameter"); | 4263 "\"open_file_cache\" must have \"max\" parameter"); |
4114 return NGX_CONF_ERROR; | 4264 return NGX_CONF_ERROR; |
4115 } | 4265 } |
4116 | 4266 |
4117 lcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive); | 4267 clcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive); |
4118 if (lcf->open_file_cache) { | 4268 if (clcf->open_file_cache) { |
4119 return NGX_CONF_OK; | 4269 return NGX_CONF_OK; |
4120 } | 4270 } |
4121 | 4271 |
4122 return NGX_CONF_ERROR; | 4272 return NGX_CONF_ERROR; |
4123 } | 4273 } |
4124 | 4274 |
4125 | 4275 |
4126 static char * | 4276 static char * |
4127 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 4277 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
4128 { | 4278 { |
4129 ngx_http_core_loc_conf_t *lcf = conf; | 4279 ngx_http_core_loc_conf_t *clcf = conf; |
4130 | 4280 |
4131 ngx_str_t *value; | 4281 ngx_str_t *value; |
4132 | 4282 |
4133 if (lcf->error_log) { | 4283 if (clcf->error_log) { |
4134 return "is duplicate"; | 4284 return "is duplicate"; |
4135 } | 4285 } |
4136 | 4286 |
4137 value = cf->args->elts; | 4287 value = cf->args->elts; |
4138 | 4288 |
4139 lcf->error_log = ngx_log_create(cf->cycle, &value[1]); | 4289 clcf->error_log = ngx_log_create(cf->cycle, &value[1]); |
4140 if (lcf->error_log == NULL) { | 4290 if (clcf->error_log == NULL) { |
4141 return NGX_CONF_ERROR; | 4291 return NGX_CONF_ERROR; |
4142 } | 4292 } |
4143 | 4293 |
4144 if (cf->args->nelts == 2) { | 4294 if (cf->args->nelts == 2) { |
4145 lcf->error_log->log_level = NGX_LOG_ERR; | 4295 clcf->error_log->log_level = NGX_LOG_ERR; |
4146 return NGX_CONF_OK; | 4296 return NGX_CONF_OK; |
4147 } | 4297 } |
4148 | 4298 |
4149 return ngx_log_set_levels(cf, lcf->error_log); | 4299 return ngx_log_set_levels(cf, clcf->error_log); |
4150 } | 4300 } |
4151 | 4301 |
4152 | 4302 |
4153 static char * | 4303 static char * |
4154 ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 4304 ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
4155 { | 4305 { |
4156 ngx_http_core_loc_conf_t *lcf = conf; | 4306 ngx_http_core_loc_conf_t *clcf = conf; |
4157 | 4307 |
4158 ngx_str_t *value; | 4308 ngx_str_t *value; |
4159 | 4309 |
4160 if (lcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) { | 4310 if (clcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) { |
4161 return "is duplicate"; | 4311 return "is duplicate"; |
4162 } | 4312 } |
4163 | 4313 |
4164 value = cf->args->elts; | 4314 value = cf->args->elts; |
4165 | 4315 |
4166 lcf->keepalive_timeout = ngx_parse_time(&value[1], 0); | 4316 clcf->keepalive_timeout = ngx_parse_time(&value[1], 0); |
4167 | 4317 |
4168 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) { | 4318 if (clcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) { |
4169 return "invalid value"; | 4319 return "invalid value"; |
4170 } | 4320 } |
4171 | 4321 |
4172 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) { | 4322 if (clcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) { |
4173 return "value must be less than 597 hours"; | 4323 return "value must be less than 597 hours"; |
4174 } | 4324 } |
4175 | 4325 |
4176 if (cf->args->nelts == 2) { | 4326 if (cf->args->nelts == 2) { |
4177 return NGX_CONF_OK; | 4327 return NGX_CONF_OK; |
4178 } | 4328 } |
4179 | 4329 |
4180 lcf->keepalive_header = ngx_parse_time(&value[2], 1); | 4330 clcf->keepalive_header = ngx_parse_time(&value[2], 1); |
4181 | 4331 |
4182 if (lcf->keepalive_header == NGX_ERROR) { | 4332 if (clcf->keepalive_header == NGX_ERROR) { |
4183 return "invalid value"; | 4333 return "invalid value"; |
4184 } | 4334 } |
4185 | 4335 |
4186 if (lcf->keepalive_header == NGX_PARSE_LARGE_TIME) { | 4336 if (clcf->keepalive_header == NGX_PARSE_LARGE_TIME) { |
4187 return "value must be less than 68 years"; | 4337 return "value must be less than 68 years"; |
4188 } | 4338 } |
4189 | 4339 |
4190 return NGX_CONF_OK; | 4340 return NGX_CONF_OK; |
4191 } | 4341 } |
4192 | 4342 |
4193 | 4343 |
4194 static char * | 4344 static char * |
4195 ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 4345 ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
4196 { | 4346 { |
4197 ngx_http_core_loc_conf_t *lcf = conf; | 4347 ngx_http_core_loc_conf_t *clcf = conf; |
4198 | 4348 |
4199 if (lcf->internal != NGX_CONF_UNSET) { | 4349 if (clcf->internal != NGX_CONF_UNSET) { |
4200 return "is duplicate"; | 4350 return "is duplicate"; |
4201 } | 4351 } |
4202 | 4352 |
4203 lcf->internal = 1; | 4353 clcf->internal = 1; |
4204 | 4354 |
4205 return NGX_CONF_OK; | 4355 return NGX_CONF_OK; |
4206 } | 4356 } |
4207 | 4357 |
4208 | 4358 |
4246 { | 4396 { |
4247 ngx_http_core_loc_conf_t *clcf = conf; | 4397 ngx_http_core_loc_conf_t *clcf = conf; |
4248 | 4398 |
4249 #if (NGX_PCRE) | 4399 #if (NGX_PCRE) |
4250 | 4400 |
4251 ngx_str_t err, *value; | 4401 ngx_str_t *value; |
4252 ngx_uint_t i; | 4402 ngx_uint_t i; |
4253 ngx_regex_elt_t *re; | 4403 ngx_regex_elt_t *re; |
4254 u_char errstr[NGX_MAX_CONF_ERRSTR]; | 4404 ngx_regex_compile_t rc; |
4405 u_char errstr[NGX_MAX_CONF_ERRSTR]; | |
4255 | 4406 |
4256 if (clcf->gzip_disable == NGX_CONF_UNSET_PTR) { | 4407 if (clcf->gzip_disable == NGX_CONF_UNSET_PTR) { |
4257 clcf->gzip_disable = ngx_array_create(cf->pool, 2, | 4408 clcf->gzip_disable = ngx_array_create(cf->pool, 2, |
4258 sizeof(ngx_regex_elt_t)); | 4409 sizeof(ngx_regex_elt_t)); |
4259 if (clcf->gzip_disable == NULL) { | 4410 if (clcf->gzip_disable == NULL) { |
4261 } | 4412 } |
4262 } | 4413 } |
4263 | 4414 |
4264 value = cf->args->elts; | 4415 value = cf->args->elts; |
4265 | 4416 |
4266 err.len = NGX_MAX_CONF_ERRSTR; | 4417 ngx_memzero(&rc, sizeof(ngx_regex_compile_t)); |
4267 err.data = errstr; | 4418 |
4419 rc.pool = cf->pool; | |
4420 rc.err.len = NGX_MAX_CONF_ERRSTR; | |
4421 rc.err.data = errstr; | |
4268 | 4422 |
4269 for (i = 1; i < cf->args->nelts; i++) { | 4423 for (i = 1; i < cf->args->nelts; i++) { |
4270 | 4424 |
4271 if (ngx_strcmp(value[1].data, "msie6") == 0) { | 4425 if (ngx_strcmp(value[i].data, "msie6") == 0) { |
4272 clcf->gzip_disable_msie6 = 1; | 4426 clcf->gzip_disable_msie6 = 1; |
4273 continue; | 4427 continue; |
4274 } | 4428 } |
4429 | |
4430 #if (NGX_HTTP_DEGRADATION) | |
4431 | |
4432 if (ngx_strcmp(value[i].data, "degradation") == 0) { | |
4433 clcf->gzip_disable_degradation = 1; | |
4434 continue; | |
4435 } | |
4436 | |
4437 #endif | |
4275 | 4438 |
4276 re = ngx_array_push(clcf->gzip_disable); | 4439 re = ngx_array_push(clcf->gzip_disable); |
4277 if (re == NULL) { | 4440 if (re == NULL) { |
4278 return NGX_CONF_ERROR; | 4441 return NGX_CONF_ERROR; |
4279 } | 4442 } |
4280 | 4443 |
4281 re->regex = ngx_regex_compile(&value[i], NGX_REGEX_CASELESS, cf->pool, | 4444 rc.pattern = value[i]; |
4282 &err); | 4445 rc.options = NGX_REGEX_CASELESS; |
4283 | 4446 |
4284 if (re->regex == NULL) { | 4447 if (ngx_regex_compile(&rc) != NGX_OK) { |
4285 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); | 4448 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err); |
4286 return NGX_CONF_ERROR; | 4449 return NGX_CONF_ERROR; |
4287 } | 4450 } |
4288 | 4451 |
4452 re->regex = rc.regex; | |
4289 re->name = value[i].data; | 4453 re->name = value[i].data; |
4290 } | 4454 } |
4291 | 4455 |
4292 return NGX_CONF_OK; | 4456 return NGX_CONF_OK; |
4293 | 4457 |
4294 #else | 4458 #else |
4295 ngx_str_t *value; | 4459 ngx_str_t *value; |
4460 ngx_uint_t i; | |
4296 | 4461 |
4297 value = cf->args->elts; | 4462 value = cf->args->elts; |
4298 | 4463 |
4299 if (cf->args->nelts == 2 && ngx_strcmp(value[1].data, "msie6") == 0) { | 4464 for (i = 1; i < cf->args->nelts; i++) { |
4300 clcf->gzip_disable_msie6 = 1; | 4465 if (ngx_strcmp(value[i].data, "msie6") == 0) { |
4301 return NGX_CONF_OK; | 4466 clcf->gzip_disable_msie6 = 1; |
4302 } | 4467 continue; |
4303 | 4468 } |
4304 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 4469 |
4305 "without PCRE library \"gzip_disable\" supports " | 4470 #if (NGX_HTTP_DEGRADATION) |
4306 "builtin \"msie6\" mask only"); | 4471 |
4307 | 4472 if (ngx_strcmp(value[i].data, "degradation") == 0) { |
4308 return NGX_CONF_ERROR; | 4473 clcf->gzip_disable_degradation = 1; |
4474 continue; | |
4475 } | |
4476 | |
4477 #endif | |
4478 | |
4479 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
4480 "without PCRE library \"gzip_disable\" supports " | |
4481 "builtin \"msie6\" and \"degradation\" mask only"); | |
4482 | |
4483 return NGX_CONF_ERROR; | |
4484 } | |
4485 | |
4486 return NGX_CONF_OK; | |
4487 | |
4309 #endif | 4488 #endif |
4310 } | 4489 } |
4311 | 4490 |
4312 #endif | 4491 #endif |
4313 | 4492 |
4346 { | 4525 { |
4347 size_t *sp = data; | 4526 size_t *sp = data; |
4348 | 4527 |
4349 if (*sp < NGX_MIN_POOL_SIZE) { | 4528 if (*sp < NGX_MIN_POOL_SIZE) { |
4350 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 4529 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
4351 "pool must be no less than %uz", NGX_MIN_POOL_SIZE); | 4530 "the pool size must be no less than %uz", |
4352 | 4531 NGX_MIN_POOL_SIZE); |
4353 return NGX_CONF_ERROR; | 4532 return NGX_CONF_ERROR; |
4354 } | 4533 } |
4355 | 4534 |
4535 if (*sp % NGX_POOL_ALIGNMENT) { | |
4536 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
4537 "the pool size must be a multiple of %uz", | |
4538 NGX_POOL_ALIGNMENT); | |
4539 return NGX_CONF_ERROR; | |
4540 } | |
4541 | |
4356 return NGX_CONF_OK; | 4542 return NGX_CONF_OK; |
4357 } | 4543 } |