Mercurial > hg > nginx-ranges
comparison src/http/ngx_http_core_module.c @ 578:f3a9e57d2e17
Merge with current.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 11 Mar 2010 21:27:17 +0300 |
parents | da3c99095432 |
children | be4f34123024 |
comparison
equal
deleted
inserted
replaced
539:5f4de8cf0d9d | 578:f3a9e57d2e17 |
---|---|
406 offsetof(ngx_http_core_loc_conf_t, aio), | 406 offsetof(ngx_http_core_loc_conf_t, aio), |
407 &ngx_http_core_aio }, | 407 &ngx_http_core_aio }, |
408 | 408 |
409 #endif | 409 #endif |
410 | 410 |
411 { ngx_string("read_ahead"), | |
412 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
413 ngx_conf_set_size_slot, | |
414 NGX_HTTP_LOC_CONF_OFFSET, | |
415 offsetof(ngx_http_core_loc_conf_t, read_ahead), | |
416 NULL }, | |
417 | |
411 { ngx_string("directio"), | 418 { ngx_string("directio"), |
412 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 419 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
413 ngx_http_core_directio, | 420 ngx_http_core_directio, |
414 NGX_HTTP_LOC_CONF_OFFSET, | 421 NGX_HTTP_LOC_CONF_OFFSET, |
415 0, | 422 0, |
774 case NGX_HTTP_CONNECTION_KEEP_ALIVE: | 781 case NGX_HTTP_CONNECTION_KEEP_ALIVE: |
775 r->keepalive = 1; | 782 r->keepalive = 1; |
776 break; | 783 break; |
777 } | 784 } |
778 | 785 |
779 if (r->keepalive && r->headers_in.msie && r->method == NGX_HTTP_POST) { | 786 if (r->keepalive) { |
780 | 787 |
781 /* | 788 if (r->headers_in.msie6) { |
782 * MSIE may wait for some time if an response for | 789 if (r->method == NGX_HTTP_POST) { |
783 * a POST request was sent over a keepalive connection | 790 /* |
784 */ | 791 * MSIE may wait for some time if an response for |
785 | 792 * a POST request was sent over a keepalive connection |
786 r->keepalive = 0; | 793 */ |
794 r->keepalive = 0; | |
795 } | |
796 | |
797 } else if (r->headers_in.safari) { | |
798 /* | |
799 * Safari may send a POST request to a closed keepalive | |
800 * connection and stalls for some time | |
801 */ | |
802 r->keepalive = 0; | |
803 } | |
787 } | 804 } |
788 | 805 |
789 if (r->headers_in.content_length_n > 0) { | 806 if (r->headers_in.content_length_n > 0) { |
790 r->lingering_close = 1; | 807 r->lingering_close = 1; |
791 | 808 |
803 if (r->unparsed_uri.len) { | 820 if (r->unparsed_uri.len) { |
804 r->valid_unparsed_uri = 1; | 821 r->valid_unparsed_uri = 1; |
805 } | 822 } |
806 | 823 |
807 r->valid_location = 1; | 824 r->valid_location = 1; |
808 r->gzip = 0; | 825 #if (NGX_HTTP_GZIP) |
826 r->gzip_tested = 0; | |
827 r->gzip_ok = 0; | |
828 r->gzip_vary = 0; | |
829 #endif | |
809 | 830 |
810 r->write_event_handler = ngx_http_core_run_phases; | 831 r->write_event_handler = ngx_http_core_run_phases; |
811 ngx_http_core_run_phases(r); | 832 ngx_http_core_run_phases(r); |
812 } | 833 } |
813 | 834 |
992 if (r->uri_changes == 0) { | 1013 if (r->uri_changes == 0) { |
993 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | 1014 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
994 "rewrite or internal redirection cycle " | 1015 "rewrite or internal redirection cycle " |
995 "while processing \"%V\"", &r->uri); | 1016 "while processing \"%V\"", &r->uri); |
996 | 1017 |
997 r->main->count++; | |
998 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 1018 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
999 return NGX_OK; | 1019 return NGX_OK; |
1000 } | 1020 } |
1001 | 1021 |
1002 r->phase_handler = ph->next; | 1022 r->phase_handler = ph->next; |
1231 of.events = clcf->open_file_cache_events; | 1251 of.events = clcf->open_file_cache_events; |
1232 | 1252 |
1233 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) | 1253 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
1234 != NGX_OK) | 1254 != NGX_OK) |
1235 { | 1255 { |
1236 if (of.err != NGX_ENOENT && of.err != NGX_ENOTDIR) { | 1256 if (of.err != NGX_ENOENT |
1257 && of.err != NGX_ENOTDIR | |
1258 && of.err != NGX_ENAMETOOLONG) | |
1259 { | |
1237 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err, | 1260 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err, |
1238 "%s \"%s\" failed", of.failed, path.data); | 1261 "%s \"%s\" failed", of.failed, path.data); |
1239 } | 1262 } |
1240 | 1263 |
1241 continue; | 1264 continue; |
1405 ngx_http_core_find_location(ngx_http_request_t *r) | 1428 ngx_http_core_find_location(ngx_http_request_t *r) |
1406 { | 1429 { |
1407 ngx_int_t rc; | 1430 ngx_int_t rc; |
1408 ngx_http_core_loc_conf_t *pclcf; | 1431 ngx_http_core_loc_conf_t *pclcf; |
1409 #if (NGX_PCRE) | 1432 #if (NGX_PCRE) |
1410 ngx_int_t n, len; | 1433 ngx_int_t n; |
1411 ngx_uint_t noregex; | 1434 ngx_uint_t noregex; |
1412 ngx_http_core_loc_conf_t *clcf, **clcfp; | 1435 ngx_http_core_loc_conf_t *clcf, **clcfp; |
1413 | 1436 |
1414 noregex = 0; | 1437 noregex = 0; |
1415 #endif | 1438 #endif |
1439 | 1462 |
1440 #if (NGX_PCRE) | 1463 #if (NGX_PCRE) |
1441 | 1464 |
1442 if (noregex == 0 && pclcf->regex_locations) { | 1465 if (noregex == 0 && pclcf->regex_locations) { |
1443 | 1466 |
1444 len = 0; | |
1445 | |
1446 for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) { | 1467 for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) { |
1447 | 1468 |
1448 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1469 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1449 "test location: ~ \"%V\"", &(*clcfp)->name); | 1470 "test location: ~ \"%V\"", &(*clcfp)->name); |
1450 | 1471 |
1451 if ((*clcfp)->captures) { | 1472 n = ngx_http_regex_exec(r, (*clcfp)->regex, &r->uri); |
1452 | 1473 |
1453 len = (NGX_HTTP_MAX_CAPTURES + 1) * 3; | 1474 if (n == NGX_OK) { |
1454 | 1475 r->loc_conf = (*clcfp)->loc_conf; |
1455 if (r->captures == NULL) { | 1476 |
1456 r->captures = ngx_palloc(r->pool, len * sizeof(int)); | 1477 /* look up nested locations */ |
1457 if (r->captures == NULL) { | 1478 |
1458 return NGX_ERROR; | 1479 rc = ngx_http_core_find_location(r); |
1459 } | 1480 |
1460 } | 1481 return (rc == NGX_ERROR) ? rc : NGX_OK; |
1461 } | 1482 } |
1462 | 1483 |
1463 n = ngx_regex_exec((*clcfp)->regex, &r->uri, r->captures, len); | 1484 if (n == NGX_DECLINED) { |
1464 | |
1465 if (n == NGX_REGEX_NO_MATCHED) { | |
1466 continue; | 1485 continue; |
1467 } | 1486 } |
1468 | 1487 |
1469 if (n < 0) { | 1488 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 } | 1489 } |
1490 } | 1490 } |
1491 #endif | 1491 #endif |
1492 | 1492 |
1493 return rc; | 1493 return rc; |
1580 { | 1580 { |
1581 u_char c, *lowcase; | 1581 u_char c, *lowcase; |
1582 size_t len; | 1582 size_t len; |
1583 ngx_uint_t i, hash; | 1583 ngx_uint_t i, hash; |
1584 | 1584 |
1585 if (types_hash->size == 0) { | |
1586 return (void *) 4; | |
1587 } | |
1588 | |
1585 if (r->headers_out.content_type.len == 0) { | 1589 if (r->headers_out.content_type.len == 0) { |
1586 return NULL; | 1590 return NULL; |
1587 } | 1591 } |
1588 | 1592 |
1589 len = r->headers_out.content_type_len; | 1593 len = r->headers_out.content_type_len; |
1763 } else { | 1767 } else { |
1764 | 1768 |
1765 #if (NGX_PCRE) | 1769 #if (NGX_PCRE) |
1766 ngx_uint_t captures; | 1770 ngx_uint_t captures; |
1767 | 1771 |
1768 captures = alias && clcf->captures; | 1772 captures = alias && clcf->regex; |
1769 reserved += captures ? 1 : r->uri.len - alias + 1; | 1773 reserved += captures ? 1 : r->uri.len - alias + 1; |
1770 #else | 1774 #else |
1771 reserved += r->uri.len - alias + 1; | 1775 reserved += r->uri.len - alias + 1; |
1772 #endif | 1776 #endif |
1773 | 1777 |
1880 ngx_uint_t p; | 1884 ngx_uint_t p; |
1881 ngx_array_t *cc; | 1885 ngx_array_t *cc; |
1882 ngx_table_elt_t *e, *d; | 1886 ngx_table_elt_t *e, *d; |
1883 ngx_http_core_loc_conf_t *clcf; | 1887 ngx_http_core_loc_conf_t *clcf; |
1884 | 1888 |
1885 if (r->gzip == 1) { | 1889 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 | 1890 |
1895 if (r != r->main | 1891 if (r != r->main |
1896 || r->headers_in.accept_encoding == NULL | 1892 || r->headers_in.accept_encoding == NULL |
1897 || ngx_strcasestrn(r->headers_in.accept_encoding->value.data, | 1893 || ngx_strcasestrn(r->headers_in.accept_encoding->value.data, |
1898 "gzip", 4 - 1) | 1894 "gzip", 4 - 1) |
2023 } | 2019 } |
2024 } | 2020 } |
2025 | 2021 |
2026 #endif | 2022 #endif |
2027 | 2023 |
2028 r->gzip = 1; | 2024 r->gzip_ok = 1; |
2029 | 2025 |
2030 return NGX_OK; | 2026 return NGX_OK; |
2031 } | 2027 } |
2032 | 2028 |
2033 #endif | 2029 #endif |
2589 static ngx_int_t | 2585 static ngx_int_t |
2590 ngx_http_core_regex_location(ngx_conf_t *cf, ngx_http_core_loc_conf_t *clcf, | 2586 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) | 2587 ngx_str_t *regex, ngx_uint_t caseless) |
2592 { | 2588 { |
2593 #if (NGX_PCRE) | 2589 #if (NGX_PCRE) |
2594 ngx_str_t err; | 2590 ngx_regex_compile_t rc; |
2595 u_char errstr[NGX_MAX_CONF_ERRSTR]; | 2591 u_char errstr[NGX_MAX_CONF_ERRSTR]; |
2596 | 2592 |
2597 err.len = NGX_MAX_CONF_ERRSTR; | 2593 ngx_memzero(&rc, sizeof(ngx_regex_compile_t)); |
2598 err.data = errstr; | 2594 |
2595 rc.pattern = *regex; | |
2596 rc.err.len = NGX_MAX_CONF_ERRSTR; | |
2597 rc.err.data = errstr; | |
2599 | 2598 |
2600 #if (NGX_HAVE_CASELESS_FILESYSTEM) | 2599 #if (NGX_HAVE_CASELESS_FILESYSTEM) |
2601 caseless = 1; | 2600 rc.options = NGX_REGEX_CASELESS; |
2601 #else | |
2602 rc.options = caseless; | |
2602 #endif | 2603 #endif |
2603 | 2604 |
2604 clcf->regex = ngx_regex_compile(regex, caseless ? NGX_REGEX_CASELESS: 0, | 2605 clcf->regex = ngx_http_regex_compile(cf, &rc); |
2605 cf->pool, &err); | |
2606 | |
2607 if (clcf->regex == NULL) { | 2606 if (clcf->regex == NULL) { |
2608 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); | |
2609 return NGX_ERROR; | 2607 return NGX_ERROR; |
2610 } | 2608 } |
2611 | 2609 |
2612 clcf->name = *regex; | 2610 clcf->name = *regex; |
2613 clcf->captures = (ngx_regex_capture_count(clcf->regex) > 0); | |
2614 | 2611 |
2615 return NGX_OK; | 2612 return NGX_OK; |
2616 | 2613 |
2617 #else | 2614 #else |
2618 | 2615 |
2626 | 2623 |
2627 | 2624 |
2628 static char * | 2625 static char * |
2629 ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 2626 ngx_http_core_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
2630 { | 2627 { |
2631 ngx_http_core_loc_conf_t *lcf = conf; | 2628 ngx_http_core_loc_conf_t *clcf = conf; |
2632 | 2629 |
2633 char *rv; | 2630 char *rv; |
2634 ngx_conf_t save; | 2631 ngx_conf_t save; |
2635 | 2632 |
2636 if (lcf->types == NULL) { | 2633 if (clcf->types == NULL) { |
2637 lcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t)); | 2634 clcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t)); |
2638 if (lcf->types == NULL) { | 2635 if (clcf->types == NULL) { |
2639 return NGX_CONF_ERROR; | 2636 return NGX_CONF_ERROR; |
2640 } | 2637 } |
2641 } | 2638 } |
2642 | 2639 |
2643 save = *cf; | 2640 save = *cf; |
2653 | 2650 |
2654 | 2651 |
2655 static char * | 2652 static char * |
2656 ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) | 2653 ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) |
2657 { | 2654 { |
2658 ngx_http_core_loc_conf_t *lcf = conf; | 2655 ngx_http_core_loc_conf_t *clcf = conf; |
2659 | 2656 |
2660 ngx_str_t *value, *content_type, *old, file; | 2657 ngx_str_t *value, *content_type, *old, file; |
2661 ngx_uint_t i, n, hash; | 2658 ngx_uint_t i, n, hash; |
2662 ngx_hash_key_t *type; | 2659 ngx_hash_key_t *type; |
2663 | 2660 |
2684 | 2681 |
2685 for (i = 1; i < cf->args->nelts; i++) { | 2682 for (i = 1; i < cf->args->nelts; i++) { |
2686 | 2683 |
2687 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len); | 2684 hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len); |
2688 | 2685 |
2689 type = lcf->types->elts; | 2686 type = clcf->types->elts; |
2690 for (n = 0; n < lcf->types->nelts; n++) { | 2687 for (n = 0; n < clcf->types->nelts; n++) { |
2691 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) { | 2688 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) { |
2692 old = type[n].value; | 2689 old = type[n].value; |
2693 type[n].value = content_type; | 2690 type[n].value = content_type; |
2694 | 2691 |
2695 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | 2692 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
2700 continue; | 2697 continue; |
2701 } | 2698 } |
2702 } | 2699 } |
2703 | 2700 |
2704 | 2701 |
2705 type = ngx_array_push(lcf->types); | 2702 type = ngx_array_push(clcf->types); |
2706 if (type == NULL) { | 2703 if (type == NULL) { |
2707 return NGX_CONF_ERROR; | 2704 return NGX_CONF_ERROR; |
2708 } | 2705 } |
2709 | 2706 |
2710 type->key = value[i]; | 2707 type->key = value[i]; |
2776 } | 2773 } |
2777 | 2774 |
2778 cmcf->variables_hash_bucket_size = | 2775 cmcf->variables_hash_bucket_size = |
2779 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size); | 2776 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size); |
2780 | 2777 |
2778 if (cmcf->ncaptures) { | |
2779 cmcf->ncaptures = (cmcf->ncaptures + 1) * 3; | |
2780 } | |
2781 | |
2781 return NGX_CONF_OK; | 2782 return NGX_CONF_OK; |
2782 } | 2783 } |
2783 | 2784 |
2784 | 2785 |
2785 static void * | 2786 static void * |
2795 /* | 2796 /* |
2796 * set by ngx_pcalloc(): | 2797 * set by ngx_pcalloc(): |
2797 * | 2798 * |
2798 * conf->client_large_buffers.num = 0; | 2799 * conf->client_large_buffers.num = 0; |
2799 */ | 2800 */ |
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 | 2801 |
2808 if (ngx_array_init(&cscf->server_names, cf->temp_pool, 4, | 2802 if (ngx_array_init(&cscf->server_names, cf->temp_pool, 4, |
2809 sizeof(ngx_http_server_name_t)) | 2803 sizeof(ngx_http_server_name_t)) |
2810 != NGX_OK) | 2804 != NGX_OK) |
2811 { | 2805 { |
2828 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) | 2822 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) |
2829 { | 2823 { |
2830 ngx_http_core_srv_conf_t *prev = parent; | 2824 ngx_http_core_srv_conf_t *prev = parent; |
2831 ngx_http_core_srv_conf_t *conf = child; | 2825 ngx_http_core_srv_conf_t *conf = child; |
2832 | 2826 |
2833 ngx_http_listen_t *ls; | |
2834 struct sockaddr_in *sin; | 2827 struct sockaddr_in *sin; |
2828 ngx_http_listen_opt_t lsopt; | |
2835 ngx_http_server_name_t *sn; | 2829 ngx_http_server_name_t *sn; |
2836 | 2830 |
2837 /* TODO: it does not merge, it inits only */ | 2831 /* 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 | 2832 |
2885 ngx_conf_merge_size_value(conf->connection_pool_size, | 2833 ngx_conf_merge_size_value(conf->connection_pool_size, |
2886 prev->connection_pool_size, 256); | 2834 prev->connection_pool_size, 256); |
2887 ngx_conf_merge_size_value(conf->request_pool_size, | 2835 ngx_conf_merge_size_value(conf->request_pool_size, |
2888 prev->request_pool_size, 4096); | 2836 prev->request_pool_size, 4096); |
2890 prev->client_header_timeout, 60000); | 2838 prev->client_header_timeout, 60000); |
2891 ngx_conf_merge_size_value(conf->client_header_buffer_size, | 2839 ngx_conf_merge_size_value(conf->client_header_buffer_size, |
2892 prev->client_header_buffer_size, 1024); | 2840 prev->client_header_buffer_size, 1024); |
2893 ngx_conf_merge_bufs_value(conf->large_client_header_buffers, | 2841 ngx_conf_merge_bufs_value(conf->large_client_header_buffers, |
2894 prev->large_client_header_buffers, | 2842 prev->large_client_header_buffers, |
2895 4, ngx_pagesize); | 2843 4, 8192); |
2896 | 2844 |
2897 if (conf->large_client_header_buffers.size < conf->connection_pool_size) { | 2845 if (conf->large_client_header_buffers.size < conf->connection_pool_size) { |
2898 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 2846 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2899 "the \"large_client_header_buffers\" size must be " | 2847 "the \"large_client_header_buffers\" size must be " |
2900 "equal to or bigger than \"connection_pool_size\""); | 2848 "equal to or bigger than \"connection_pool_size\""); |
2907 ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1); | 2855 ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1); |
2908 | 2856 |
2909 ngx_conf_merge_value(conf->underscores_in_headers, | 2857 ngx_conf_merge_value(conf->underscores_in_headers, |
2910 prev->underscores_in_headers, 0); | 2858 prev->underscores_in_headers, 0); |
2911 | 2859 |
2860 if (!conf->listen) { | |
2861 ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t)); | |
2862 | |
2863 sin = &lsopt.u.sockaddr_in; | |
2864 | |
2865 sin->sin_family = AF_INET; | |
2866 #if (NGX_WIN32) | |
2867 sin->sin_port = htons(80); | |
2868 #else | |
2869 sin->sin_port = htons((getuid() == 0) ? 80 : 8000); | |
2870 #endif | |
2871 sin->sin_addr.s_addr = INADDR_ANY; | |
2872 | |
2873 lsopt.socklen = sizeof(struct sockaddr_in); | |
2874 | |
2875 lsopt.backlog = NGX_LISTEN_BACKLOG; | |
2876 lsopt.rcvbuf = -1; | |
2877 lsopt.sndbuf = -1; | |
2878 lsopt.wildcard = 1; | |
2879 | |
2880 (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr, | |
2881 NGX_SOCKADDR_STRLEN, 1); | |
2882 | |
2883 if (ngx_http_add_listen(cf, conf, &lsopt) == NGX_OK) { | |
2884 return NGX_CONF_OK; | |
2885 } | |
2886 } | |
2887 | |
2888 if (conf->server_name.data == NULL) { | |
2889 conf->server_name = cf->cycle->hostname; | |
2890 | |
2891 sn = ngx_array_push(&conf->server_names); | |
2892 if (sn == NULL) { | |
2893 return NGX_CONF_ERROR; | |
2894 } | |
2895 | |
2896 #if (NGX_PCRE) | |
2897 sn->regex = NULL; | |
2898 #endif | |
2899 sn->server = conf; | |
2900 sn->name.len = conf->server_name.len; | |
2901 sn->name.data = conf->server_name.data; | |
2902 } | |
2903 | |
2912 return NGX_CONF_OK; | 2904 return NGX_CONF_OK; |
2913 } | 2905 } |
2914 | 2906 |
2915 | 2907 |
2916 static void * | 2908 static void * |
2917 ngx_http_core_create_loc_conf(ngx_conf_t *cf) | 2909 ngx_http_core_create_loc_conf(ngx_conf_t *cf) |
2918 { | 2910 { |
2919 ngx_http_core_loc_conf_t *lcf; | 2911 ngx_http_core_loc_conf_t *clcf; |
2920 | 2912 |
2921 lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)); | 2913 clcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_core_loc_conf_t)); |
2922 if (lcf == NULL) { | 2914 if (clcf == NULL) { |
2923 return NULL; | 2915 return NULL; |
2924 } | 2916 } |
2925 | 2917 |
2926 /* | 2918 /* |
2927 * set by ngx_pcalloc(): | 2919 * set by ngx_pcalloc(): |
2928 * | 2920 * |
2929 * lcf->root = { 0, NULL }; | 2921 * clcf->root = { 0, NULL }; |
2930 * lcf->limit_except = 0; | 2922 * clcf->limit_except = 0; |
2931 * lcf->post_action = { 0, NULL }; | 2923 * clcf->post_action = { 0, NULL }; |
2932 * lcf->types = NULL; | 2924 * clcf->types = NULL; |
2933 * lcf->default_type = { 0, NULL }; | 2925 * clcf->default_type = { 0, NULL }; |
2934 * lcf->error_log = NULL; | 2926 * clcf->error_log = NULL; |
2935 * lcf->error_pages = NULL; | 2927 * clcf->error_pages = NULL; |
2936 * lcf->try_files = NULL; | 2928 * clcf->try_files = NULL; |
2937 * lcf->client_body_path = NULL; | 2929 * clcf->client_body_path = NULL; |
2938 * lcf->regex = NULL; | 2930 * clcf->regex = NULL; |
2939 * lcf->exact_match = 0; | 2931 * clcf->exact_match = 0; |
2940 * lcf->auto_redirect = 0; | 2932 * clcf->auto_redirect = 0; |
2941 * lcf->alias = 0; | 2933 * clcf->alias = 0; |
2942 * lcf->gzip_proxied = 0; | 2934 * clcf->gzip_proxied = 0; |
2943 */ | 2935 */ |
2944 | 2936 |
2945 lcf->client_max_body_size = NGX_CONF_UNSET; | 2937 clcf->client_max_body_size = NGX_CONF_UNSET; |
2946 lcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE; | 2938 clcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE; |
2947 lcf->client_body_timeout = NGX_CONF_UNSET_MSEC; | 2939 clcf->client_body_timeout = NGX_CONF_UNSET_MSEC; |
2948 lcf->satisfy = NGX_CONF_UNSET_UINT; | 2940 clcf->satisfy = NGX_CONF_UNSET_UINT; |
2949 lcf->if_modified_since = NGX_CONF_UNSET_UINT; | 2941 clcf->if_modified_since = NGX_CONF_UNSET_UINT; |
2950 lcf->client_body_in_file_only = NGX_CONF_UNSET_UINT; | 2942 clcf->client_body_in_file_only = NGX_CONF_UNSET_UINT; |
2951 lcf->client_body_in_single_buffer = NGX_CONF_UNSET; | 2943 clcf->client_body_in_single_buffer = NGX_CONF_UNSET; |
2952 lcf->internal = NGX_CONF_UNSET; | 2944 clcf->internal = NGX_CONF_UNSET; |
2953 lcf->sendfile = NGX_CONF_UNSET; | 2945 clcf->sendfile = NGX_CONF_UNSET; |
2954 lcf->sendfile_max_chunk = NGX_CONF_UNSET_SIZE; | 2946 clcf->sendfile_max_chunk = NGX_CONF_UNSET_SIZE; |
2955 #if (NGX_HAVE_FILE_AIO) | 2947 #if (NGX_HAVE_FILE_AIO) |
2956 lcf->aio = NGX_CONF_UNSET; | 2948 clcf->aio = NGX_CONF_UNSET; |
2957 #endif | 2949 #endif |
2958 lcf->directio = NGX_CONF_UNSET; | 2950 clcf->read_ahead = NGX_CONF_UNSET_SIZE; |
2959 lcf->directio_alignment = NGX_CONF_UNSET; | 2951 clcf->directio = NGX_CONF_UNSET; |
2960 lcf->tcp_nopush = NGX_CONF_UNSET; | 2952 clcf->directio_alignment = NGX_CONF_UNSET; |
2961 lcf->tcp_nodelay = NGX_CONF_UNSET; | 2953 clcf->tcp_nopush = NGX_CONF_UNSET; |
2962 lcf->send_timeout = NGX_CONF_UNSET_MSEC; | 2954 clcf->tcp_nodelay = NGX_CONF_UNSET; |
2963 lcf->send_lowat = NGX_CONF_UNSET_SIZE; | 2955 clcf->send_timeout = NGX_CONF_UNSET_MSEC; |
2964 lcf->postpone_output = NGX_CONF_UNSET_SIZE; | 2956 clcf->send_lowat = NGX_CONF_UNSET_SIZE; |
2965 lcf->limit_rate = NGX_CONF_UNSET_SIZE; | 2957 clcf->postpone_output = NGX_CONF_UNSET_SIZE; |
2966 lcf->limit_rate_after = NGX_CONF_UNSET_SIZE; | 2958 clcf->limit_rate = NGX_CONF_UNSET_SIZE; |
2967 lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC; | 2959 clcf->limit_rate_after = NGX_CONF_UNSET_SIZE; |
2968 lcf->keepalive_header = NGX_CONF_UNSET; | 2960 clcf->keepalive_timeout = NGX_CONF_UNSET_MSEC; |
2969 lcf->keepalive_requests = NGX_CONF_UNSET_UINT; | 2961 clcf->keepalive_header = NGX_CONF_UNSET; |
2970 lcf->lingering_time = NGX_CONF_UNSET_MSEC; | 2962 clcf->keepalive_requests = NGX_CONF_UNSET_UINT; |
2971 lcf->lingering_timeout = NGX_CONF_UNSET_MSEC; | 2963 clcf->lingering_time = NGX_CONF_UNSET_MSEC; |
2972 lcf->resolver_timeout = NGX_CONF_UNSET_MSEC; | 2964 clcf->lingering_timeout = NGX_CONF_UNSET_MSEC; |
2973 lcf->reset_timedout_connection = NGX_CONF_UNSET; | 2965 clcf->resolver_timeout = NGX_CONF_UNSET_MSEC; |
2974 lcf->server_name_in_redirect = NGX_CONF_UNSET; | 2966 clcf->reset_timedout_connection = NGX_CONF_UNSET; |
2975 lcf->port_in_redirect = NGX_CONF_UNSET; | 2967 clcf->server_name_in_redirect = NGX_CONF_UNSET; |
2976 lcf->msie_padding = NGX_CONF_UNSET; | 2968 clcf->port_in_redirect = NGX_CONF_UNSET; |
2977 lcf->msie_refresh = NGX_CONF_UNSET; | 2969 clcf->msie_padding = NGX_CONF_UNSET; |
2978 lcf->log_not_found = NGX_CONF_UNSET; | 2970 clcf->msie_refresh = NGX_CONF_UNSET; |
2979 lcf->log_subrequest = NGX_CONF_UNSET; | 2971 clcf->log_not_found = NGX_CONF_UNSET; |
2980 lcf->recursive_error_pages = NGX_CONF_UNSET; | 2972 clcf->log_subrequest = NGX_CONF_UNSET; |
2981 lcf->server_tokens = NGX_CONF_UNSET; | 2973 clcf->recursive_error_pages = NGX_CONF_UNSET; |
2982 lcf->types_hash_max_size = NGX_CONF_UNSET_UINT; | 2974 clcf->server_tokens = NGX_CONF_UNSET; |
2983 lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT; | 2975 clcf->types_hash_max_size = NGX_CONF_UNSET_UINT; |
2984 | 2976 clcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT; |
2985 lcf->open_file_cache = NGX_CONF_UNSET_PTR; | 2977 |
2986 lcf->open_file_cache_valid = NGX_CONF_UNSET; | 2978 clcf->open_file_cache = NGX_CONF_UNSET_PTR; |
2987 lcf->open_file_cache_min_uses = NGX_CONF_UNSET_UINT; | 2979 clcf->open_file_cache_valid = NGX_CONF_UNSET; |
2988 lcf->open_file_cache_errors = NGX_CONF_UNSET; | 2980 clcf->open_file_cache_min_uses = NGX_CONF_UNSET_UINT; |
2989 lcf->open_file_cache_events = NGX_CONF_UNSET; | 2981 clcf->open_file_cache_errors = NGX_CONF_UNSET; |
2982 clcf->open_file_cache_events = NGX_CONF_UNSET; | |
2990 | 2983 |
2991 #if (NGX_HTTP_GZIP) | 2984 #if (NGX_HTTP_GZIP) |
2992 lcf->gzip_vary = NGX_CONF_UNSET; | 2985 clcf->gzip_vary = NGX_CONF_UNSET; |
2993 lcf->gzip_http_version = NGX_CONF_UNSET_UINT; | 2986 clcf->gzip_http_version = NGX_CONF_UNSET_UINT; |
2994 #if (NGX_PCRE) | 2987 #if (NGX_PCRE) |
2995 lcf->gzip_disable = NGX_CONF_UNSET_PTR; | 2988 clcf->gzip_disable = NGX_CONF_UNSET_PTR; |
2996 lcf->gzip_disable_msie6 = 3; | 2989 clcf->gzip_disable_msie6 = 3; |
2997 #endif | 2990 #endif |
2998 #endif | 2991 #endif |
2999 | 2992 |
3000 return lcf; | 2993 return clcf; |
3001 } | 2994 } |
3002 | 2995 |
3003 | 2996 |
3004 static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html"); | 2997 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"); | 2998 static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif"); |
3154 ngx_conf_merge_size_value(conf->sendfile_max_chunk, | 3147 ngx_conf_merge_size_value(conf->sendfile_max_chunk, |
3155 prev->sendfile_max_chunk, 0); | 3148 prev->sendfile_max_chunk, 0); |
3156 #if (NGX_HAVE_FILE_AIO) | 3149 #if (NGX_HAVE_FILE_AIO) |
3157 ngx_conf_merge_value(conf->aio, prev->aio, 0); | 3150 ngx_conf_merge_value(conf->aio, prev->aio, 0); |
3158 #endif | 3151 #endif |
3152 ngx_conf_merge_size_value(conf->read_ahead, prev->read_ahead, 0); | |
3159 ngx_conf_merge_off_value(conf->directio, prev->directio, | 3153 ngx_conf_merge_off_value(conf->directio, prev->directio, |
3160 NGX_MAX_OFF_T_VALUE); | 3154 NGX_MAX_OFF_T_VALUE); |
3161 ngx_conf_merge_off_value(conf->directio_alignment, prev->directio_alignment, | 3155 ngx_conf_merge_off_value(conf->directio_alignment, prev->directio_alignment, |
3162 512); | 3156 512); |
3163 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0); | 3157 ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0); |
3260 | 3254 |
3261 | 3255 |
3262 static char * | 3256 static char * |
3263 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 3257 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
3264 { | 3258 { |
3265 ngx_http_core_srv_conf_t *scf = conf; | 3259 ngx_http_core_srv_conf_t *cscf = conf; |
3266 | 3260 |
3267 ngx_str_t *value, size; | 3261 ngx_str_t *value, size; |
3268 ngx_url_t u; | 3262 ngx_url_t u; |
3269 ngx_uint_t n; | 3263 ngx_uint_t n; |
3270 ngx_http_listen_t *ls; | 3264 ngx_http_listen_opt_t lsopt; |
3271 | 3265 |
3272 /* | 3266 cscf->listen = 1; |
3273 * TODO: check duplicate 'listen' directives, | |
3274 * add resolved name to server names ??? | |
3275 */ | |
3276 | 3267 |
3277 value = cf->args->elts; | 3268 value = cf->args->elts; |
3278 | 3269 |
3279 ngx_memzero(&u, sizeof(ngx_url_t)); | 3270 ngx_memzero(&u, sizeof(ngx_url_t)); |
3280 | 3271 |
3290 } | 3281 } |
3291 | 3282 |
3292 return NGX_CONF_ERROR; | 3283 return NGX_CONF_ERROR; |
3293 } | 3284 } |
3294 | 3285 |
3295 ls = ngx_array_push(&scf->listen); | 3286 ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t)); |
3296 if (ls == NULL) { | 3287 |
3297 return NGX_CONF_ERROR; | 3288 ngx_memcpy(&lsopt.u.sockaddr, u.sockaddr, u.socklen); |
3298 } | 3289 |
3299 | 3290 lsopt.socklen = u.socklen; |
3300 ngx_memzero(ls, sizeof(ngx_http_listen_t)); | 3291 lsopt.backlog = NGX_LISTEN_BACKLOG; |
3301 | 3292 lsopt.rcvbuf = -1; |
3302 ngx_memcpy(ls->sockaddr, u.sockaddr, u.socklen); | 3293 lsopt.sndbuf = -1; |
3303 | 3294 lsopt.wildcard = u.wildcard; |
3304 ls->socklen = u.socklen; | 3295 |
3305 ls->file_name = cf->conf_file->file.name.data; | 3296 (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr, |
3306 ls->line = cf->conf_file->line; | |
3307 ls->conf.backlog = NGX_LISTEN_BACKLOG; | |
3308 ls->conf.rcvbuf = -1; | |
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); | 3297 NGX_SOCKADDR_STRLEN, 1); |
3314 | 3298 |
3315 if (cf->args->nelts == 2) { | 3299 for (n = 2; n < cf->args->nelts; n++) { |
3316 return NGX_CONF_OK; | 3300 |
3317 } | 3301 if (ngx_strcmp(value[n].data, "default_server") == 0 |
3318 | 3302 || ngx_strcmp(value[n].data, "default") == 0) |
3319 if (ngx_strcmp(value[2].data, "default") == 0) { | 3303 { |
3320 ls->conf.default_server = 1; | 3304 lsopt.default_server = 1; |
3321 n = 3; | 3305 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 } | 3306 } |
3336 | 3307 |
3337 if (ngx_strcmp(value[n].data, "bind") == 0) { | 3308 if (ngx_strcmp(value[n].data, "bind") == 0) { |
3338 ls->conf.bind = 1; | 3309 lsopt.set = 1; |
3310 lsopt.bind = 1; | |
3339 continue; | 3311 continue; |
3340 } | 3312 } |
3341 | 3313 |
3342 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) { | 3314 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) { |
3343 ls->conf.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8); | 3315 lsopt.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8); |
3344 ls->conf.bind = 1; | 3316 lsopt.set = 1; |
3345 | 3317 lsopt.bind = 1; |
3346 if (ls->conf.backlog == NGX_ERROR || ls->conf.backlog == 0) { | 3318 |
3319 if (lsopt.backlog == NGX_ERROR || lsopt.backlog == 0) { | |
3347 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3320 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3348 "invalid backlog \"%V\"", &value[n]); | 3321 "invalid backlog \"%V\"", &value[n]); |
3349 return NGX_CONF_ERROR; | 3322 return NGX_CONF_ERROR; |
3350 } | 3323 } |
3351 | 3324 |
3354 | 3327 |
3355 if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) { | 3328 if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) { |
3356 size.len = value[n].len - 7; | 3329 size.len = value[n].len - 7; |
3357 size.data = value[n].data + 7; | 3330 size.data = value[n].data + 7; |
3358 | 3331 |
3359 ls->conf.rcvbuf = ngx_parse_size(&size); | 3332 lsopt.rcvbuf = ngx_parse_size(&size); |
3360 ls->conf.bind = 1; | 3333 lsopt.set = 1; |
3361 | 3334 lsopt.bind = 1; |
3362 if (ls->conf.rcvbuf == NGX_ERROR) { | 3335 |
3336 if (lsopt.rcvbuf == NGX_ERROR) { | |
3363 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3337 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3364 "invalid rcvbuf \"%V\"", &value[n]); | 3338 "invalid rcvbuf \"%V\"", &value[n]); |
3365 return NGX_CONF_ERROR; | 3339 return NGX_CONF_ERROR; |
3366 } | 3340 } |
3367 | 3341 |
3370 | 3344 |
3371 if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) { | 3345 if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) { |
3372 size.len = value[n].len - 7; | 3346 size.len = value[n].len - 7; |
3373 size.data = value[n].data + 7; | 3347 size.data = value[n].data + 7; |
3374 | 3348 |
3375 ls->conf.sndbuf = ngx_parse_size(&size); | 3349 lsopt.sndbuf = ngx_parse_size(&size); |
3376 ls->conf.bind = 1; | 3350 lsopt.set = 1; |
3377 | 3351 lsopt.bind = 1; |
3378 if (ls->conf.sndbuf == NGX_ERROR) { | 3352 |
3353 if (lsopt.sndbuf == NGX_ERROR) { | |
3379 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3354 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3380 "invalid sndbuf \"%V\"", &value[n]); | 3355 "invalid sndbuf \"%V\"", &value[n]); |
3381 return NGX_CONF_ERROR; | 3356 return NGX_CONF_ERROR; |
3382 } | 3357 } |
3383 | 3358 |
3384 continue; | 3359 continue; |
3385 } | 3360 } |
3386 | 3361 |
3387 if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) { | 3362 if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) { |
3388 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) | 3363 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) |
3389 ls->conf.accept_filter = (char *) &value[n].data[14]; | 3364 lsopt.accept_filter = (char *) &value[n].data[14]; |
3390 ls->conf.bind = 1; | 3365 lsopt.set = 1; |
3366 lsopt.bind = 1; | |
3391 #else | 3367 #else |
3392 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3368 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3393 "accept filters \"%V\" are not supported " | 3369 "accept filters \"%V\" are not supported " |
3394 "on this platform, ignored", | 3370 "on this platform, ignored", |
3395 &value[n]); | 3371 &value[n]); |
3397 continue; | 3373 continue; |
3398 } | 3374 } |
3399 | 3375 |
3400 if (ngx_strcmp(value[n].data, "deferred") == 0) { | 3376 if (ngx_strcmp(value[n].data, "deferred") == 0) { |
3401 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT) | 3377 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT) |
3402 ls->conf.deferred_accept = 1; | 3378 lsopt.deferred_accept = 1; |
3403 ls->conf.bind = 1; | 3379 lsopt.set = 1; |
3380 lsopt.bind = 1; | |
3404 #else | 3381 #else |
3405 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3382 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3406 "the deferred accept is not supported " | 3383 "the deferred accept is not supported " |
3407 "on this platform, ignored"); | 3384 "on this platform, ignored"); |
3408 #endif | 3385 #endif |
3411 | 3388 |
3412 if (ngx_strncmp(value[n].data, "ipv6only=o", 10) == 0) { | 3389 if (ngx_strncmp(value[n].data, "ipv6only=o", 10) == 0) { |
3413 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) | 3390 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) |
3414 struct sockaddr *sa; | 3391 struct sockaddr *sa; |
3415 | 3392 |
3416 sa = (struct sockaddr *) ls->sockaddr; | 3393 sa = &lsopt.u.sockaddr; |
3417 | 3394 |
3418 if (sa->sa_family == AF_INET6) { | 3395 if (sa->sa_family == AF_INET6) { |
3419 | 3396 |
3420 if (ngx_strcmp(&value[n].data[10], "n") == 0) { | 3397 if (ngx_strcmp(&value[n].data[10], "n") == 0) { |
3421 ls->conf.ipv6only = 1; | 3398 lsopt.ipv6only = 1; |
3422 | 3399 |
3423 } else if (ngx_strcmp(&value[n].data[10], "ff") == 0) { | 3400 } else if (ngx_strcmp(&value[n].data[10], "ff") == 0) { |
3424 ls->conf.ipv6only = 2; | 3401 lsopt.ipv6only = 2; |
3425 | 3402 |
3426 } else { | 3403 } else { |
3427 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3404 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3428 "invalid ipv6only flags \"%s\"", | 3405 "invalid ipv6only flags \"%s\"", |
3429 &value[n].data[9]); | 3406 &value[n].data[9]); |
3430 return NGX_CONF_ERROR; | 3407 return NGX_CONF_ERROR; |
3431 } | 3408 } |
3432 | 3409 |
3433 ls->conf.bind = 1; | 3410 lsopt.set = 1; |
3411 lsopt.bind = 1; | |
3434 | 3412 |
3435 } else { | 3413 } else { |
3436 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3414 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3437 "ipv6only is not supported " | 3415 "ipv6only is not supported " |
3438 "on addr \"%s\", ignored", | 3416 "on addr \"%s\", ignored", lsopt.addr); |
3439 ls->conf.addr); | |
3440 } | 3417 } |
3441 | 3418 |
3442 continue; | 3419 continue; |
3443 #else | 3420 #else |
3444 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3421 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3448 #endif | 3425 #endif |
3449 } | 3426 } |
3450 | 3427 |
3451 if (ngx_strcmp(value[n].data, "ssl") == 0) { | 3428 if (ngx_strcmp(value[n].data, "ssl") == 0) { |
3452 #if (NGX_HTTP_SSL) | 3429 #if (NGX_HTTP_SSL) |
3453 ls->conf.ssl = 1; | 3430 lsopt.set = 1; |
3431 lsopt.ssl = 1; | |
3454 continue; | 3432 continue; |
3455 #else | 3433 #else |
3456 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3434 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3457 "the \"ssl\" parameter requires " | 3435 "the \"ssl\" parameter requires " |
3458 "ngx_http_ssl_module"); | 3436 "ngx_http_ssl_module"); |
3463 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3441 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3464 "the invalid \"%V\" parameter", &value[n]); | 3442 "the invalid \"%V\" parameter", &value[n]); |
3465 return NGX_CONF_ERROR; | 3443 return NGX_CONF_ERROR; |
3466 } | 3444 } |
3467 | 3445 |
3468 return NGX_CONF_OK; | 3446 if (ngx_http_add_listen(cf, cscf, &lsopt) == NGX_OK) { |
3447 return NGX_CONF_OK; | |
3448 } | |
3449 | |
3450 return NGX_CONF_ERROR; | |
3469 } | 3451 } |
3470 | 3452 |
3471 | 3453 |
3472 static char * | 3454 static char * |
3473 ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 3455 ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
3535 return NGX_CONF_ERROR; | 3517 return NGX_CONF_ERROR; |
3536 } | 3518 } |
3537 | 3519 |
3538 #if (NGX_PCRE) | 3520 #if (NGX_PCRE) |
3539 sn->regex = NULL; | 3521 sn->regex = NULL; |
3540 sn->captures = 0; | |
3541 #endif | 3522 #endif |
3542 sn->core_srv_conf = cscf; | 3523 sn->server = cscf; |
3543 sn->name = value[i]; | 3524 sn->name = value[i]; |
3544 | 3525 |
3545 if (value[i].data[0] != '~') { | 3526 if (value[i].data[0] != '~') { |
3527 ngx_strlow(sn->name.data, sn->name.data, sn->name.len); | |
3546 continue; | 3528 continue; |
3547 } | 3529 } |
3548 | 3530 |
3549 #if (NGX_PCRE) | 3531 #if (NGX_PCRE) |
3550 { | 3532 { |
3551 ngx_str_t err; | 3533 u_char *p; |
3552 u_char errstr[NGX_MAX_CONF_ERRSTR]; | 3534 ngx_regex_compile_t rc; |
3535 u_char errstr[NGX_MAX_CONF_ERRSTR]; | |
3553 | 3536 |
3554 if (value[i].len == 1) { | 3537 if (value[i].len == 1) { |
3555 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3538 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3556 "empty regex in server name \"%V\"", &value[i]); | 3539 "empty regex in server name \"%V\"", &value[i]); |
3557 return NGX_CONF_ERROR; | 3540 return NGX_CONF_ERROR; |
3558 } | 3541 } |
3559 | 3542 |
3560 err.len = NGX_MAX_CONF_ERRSTR; | |
3561 err.data = errstr; | |
3562 | |
3563 value[i].len--; | 3543 value[i].len--; |
3564 value[i].data++; | 3544 value[i].data++; |
3565 | 3545 |
3566 sn->regex = ngx_regex_compile(&value[i], 0, cf->pool, &err); | 3546 ngx_memzero(&rc, sizeof(ngx_regex_compile_t)); |
3567 | 3547 |
3548 rc.pattern = value[i]; | |
3549 rc.err.len = NGX_MAX_CONF_ERRSTR; | |
3550 rc.err.data = errstr; | |
3551 | |
3552 for (p = value[i].data; p < value[i].data + value[i].len; p++) { | |
3553 if (*p >= 'A' && *p <= 'Z') { | |
3554 rc.options = NGX_REGEX_CASELESS; | |
3555 break; | |
3556 } | |
3557 } | |
3558 | |
3559 sn->regex = ngx_http_regex_compile(cf, &rc); | |
3568 if (sn->regex == NULL) { | 3560 if (sn->regex == NULL) { |
3569 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); | |
3570 return NGX_CONF_ERROR; | 3561 return NGX_CONF_ERROR; |
3571 } | 3562 } |
3572 | 3563 |
3573 sn->captures = (ngx_regex_capture_count(sn->regex) > 0); | |
3574 sn->name = value[i]; | 3564 sn->name = value[i]; |
3565 cscf->captures = (rc.captures > 0); | |
3575 } | 3566 } |
3576 #else | 3567 #else |
3577 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3568 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3578 "the using of the regex \"%V\" " | 3569 "the using of the regex \"%V\" " |
3579 "requires PCRE library", &value[i]); | 3570 "requires PCRE library", &value[i]); |
3587 | 3578 |
3588 | 3579 |
3589 static char * | 3580 static char * |
3590 ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 3581 ngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
3591 { | 3582 { |
3592 ngx_http_core_loc_conf_t *lcf = conf; | 3583 ngx_http_core_loc_conf_t *clcf = conf; |
3593 | 3584 |
3594 ngx_str_t *value; | 3585 ngx_str_t *value; |
3595 ngx_uint_t alias, n; | 3586 ngx_uint_t alias, n; |
3596 ngx_http_script_compile_t sc; | 3587 ngx_http_script_compile_t sc; |
3597 | 3588 |
3598 alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0; | 3589 alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0; |
3599 | 3590 |
3600 if (lcf->root.data) { | 3591 if (clcf->root.data) { |
3601 | 3592 |
3602 /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */ | 3593 /* the (ngx_uint_t) cast is required by gcc 2.7.2.3 */ |
3603 | 3594 |
3604 if ((ngx_uint_t) lcf->alias == alias) { | 3595 if ((ngx_uint_t) clcf->alias == alias) { |
3605 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3596 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3606 "\"%V\" directive is duplicate", | 3597 "\"%V\" directive is duplicate", |
3607 &cmd->name); | 3598 &cmd->name); |
3608 } else { | 3599 } else { |
3609 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3600 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3610 "\"%V\" directive is duplicate, " | 3601 "\"%V\" directive is duplicate, " |
3611 "\"%s\" directive is specified before", | 3602 "\"%s\" directive is specified before", |
3612 &cmd->name, lcf->alias ? "alias" : "root"); | 3603 &cmd->name, clcf->alias ? "alias" : "root"); |
3613 } | 3604 } |
3614 | 3605 |
3615 return NGX_CONF_ERROR; | 3606 return NGX_CONF_ERROR; |
3616 } | 3607 } |
3617 | 3608 |
3618 if (lcf->named && alias) { | 3609 if (clcf->named && alias) { |
3619 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3610 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3620 "the \"alias\" directive may not be used " | 3611 "the \"alias\" directive may not be used " |
3621 "inside named location"); | 3612 "inside named location"); |
3622 | 3613 |
3623 return NGX_CONF_ERROR; | 3614 return NGX_CONF_ERROR; |
3645 &cmd->name); | 3636 &cmd->name); |
3646 | 3637 |
3647 return NGX_CONF_ERROR; | 3638 return NGX_CONF_ERROR; |
3648 } | 3639 } |
3649 | 3640 |
3650 lcf->alias = alias; | 3641 clcf->alias = alias; |
3651 lcf->root = value[1]; | 3642 clcf->root = value[1]; |
3652 | 3643 |
3653 if (!alias && lcf->root.data[lcf->root.len - 1] == '/') { | 3644 if (!alias && clcf->root.data[clcf->root.len - 1] == '/') { |
3654 lcf->root.len--; | 3645 clcf->root.len--; |
3655 } | 3646 } |
3656 | 3647 |
3657 if (lcf->root.data[0] != '$') { | 3648 if (clcf->root.data[0] != '$') { |
3658 if (ngx_conf_full_name(cf->cycle, &lcf->root, 0) != NGX_OK) { | 3649 if (ngx_conf_full_name(cf->cycle, &clcf->root, 0) != NGX_OK) { |
3659 return NGX_CONF_ERROR; | 3650 return NGX_CONF_ERROR; |
3660 } | 3651 } |
3661 } | 3652 } |
3662 | 3653 |
3663 n = ngx_http_script_variables_count(&lcf->root); | 3654 n = ngx_http_script_variables_count(&clcf->root); |
3664 | 3655 |
3665 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | 3656 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); |
3666 | 3657 |
3667 if (n) { | 3658 if (n) { |
3668 sc.cf = cf; | 3659 sc.cf = cf; |
3669 sc.source = &lcf->root; | 3660 sc.source = &clcf->root; |
3670 sc.lengths = &lcf->root_lengths; | 3661 sc.lengths = &clcf->root_lengths; |
3671 sc.values = &lcf->root_values; | 3662 sc.values = &clcf->root_values; |
3672 sc.variables = n; | 3663 sc.variables = n; |
3673 sc.complete_lengths = 1; | 3664 sc.complete_lengths = 1; |
3674 sc.complete_values = 1; | 3665 sc.complete_values = 1; |
3675 | 3666 |
3676 if (ngx_http_script_compile(&sc) != NGX_OK) { | 3667 if (ngx_http_script_compile(&sc) != NGX_OK) { |
3677 return NGX_CONF_ERROR; | 3668 return NGX_CONF_ERROR; |
3678 } | 3669 } |
3679 } | 3670 } |
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 | 3671 |
3695 return NGX_CONF_OK; | 3672 return NGX_CONF_OK; |
3696 } | 3673 } |
3697 | 3674 |
3698 | 3675 |
3841 | 3818 |
3842 | 3819 |
3843 static char * | 3820 static char * |
3844 ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 3821 ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
3845 { | 3822 { |
3846 ngx_http_core_loc_conf_t *lcf = conf; | 3823 ngx_http_core_loc_conf_t *clcf = conf; |
3847 | 3824 |
3848 u_char *p; | 3825 u_char *p; |
3849 ngx_int_t overwrite; | 3826 ngx_int_t overwrite; |
3850 ngx_str_t *value, uri, args; | 3827 ngx_str_t *value, uri, args; |
3851 ngx_uint_t i, n; | 3828 ngx_uint_t i, n; |
3852 ngx_http_err_page_t *err; | 3829 ngx_http_err_page_t *err; |
3853 ngx_http_complex_value_t cv; | 3830 ngx_http_complex_value_t cv; |
3854 ngx_http_compile_complex_value_t ccv; | 3831 ngx_http_compile_complex_value_t ccv; |
3855 | 3832 |
3856 if (lcf->error_pages == NULL) { | 3833 if (clcf->error_pages == NULL) { |
3857 lcf->error_pages = ngx_array_create(cf->pool, 4, | 3834 clcf->error_pages = ngx_array_create(cf->pool, 4, |
3858 sizeof(ngx_http_err_page_t)); | 3835 sizeof(ngx_http_err_page_t)); |
3859 if (lcf->error_pages == NULL) { | 3836 if (clcf->error_pages == NULL) { |
3860 return NGX_CONF_ERROR; | 3837 return NGX_CONF_ERROR; |
3861 } | 3838 } |
3862 } | 3839 } |
3863 | 3840 |
3864 value = cf->args->elts; | 3841 value = cf->args->elts; |
3918 args.data = p; | 3895 args.data = p; |
3919 } | 3896 } |
3920 } | 3897 } |
3921 | 3898 |
3922 for (i = 1; i < cf->args->nelts - n; i++) { | 3899 for (i = 1; i < cf->args->nelts - n; i++) { |
3923 err = ngx_array_push(lcf->error_pages); | 3900 err = ngx_array_push(clcf->error_pages); |
3924 if (err == NULL) { | 3901 if (err == NULL) { |
3925 return NGX_CONF_ERROR; | 3902 return NGX_CONF_ERROR; |
3926 } | 3903 } |
3927 | 3904 |
3928 err->status = ngx_atoi(value[i].data, value[i].len); | 3905 err->status = ngx_atoi(value[i].data, value[i].len); |
3931 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3908 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3932 "invalid value \"%V\"", &value[i]); | 3909 "invalid value \"%V\"", &value[i]); |
3933 return NGX_CONF_ERROR; | 3910 return NGX_CONF_ERROR; |
3934 } | 3911 } |
3935 | 3912 |
3936 if (err->status < 400 || err->status > 599) { | 3913 if (err->status < 300 || err->status > 599) { |
3937 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 3914 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3938 "value \"%V\" must be between 400 and 599", | 3915 "value \"%V\" must be between 300 and 599", |
3939 &value[i]); | 3916 &value[i]); |
3940 return NGX_CONF_ERROR; | 3917 return NGX_CONF_ERROR; |
3941 } | 3918 } |
3942 | 3919 |
3943 if (overwrite >= 0) { | 3920 if (overwrite >= 0) { |
4046 | 4023 |
4047 | 4024 |
4048 static char * | 4025 static char * |
4049 ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 4026 ngx_http_core_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
4050 { | 4027 { |
4051 ngx_http_core_loc_conf_t *lcf = conf; | 4028 ngx_http_core_loc_conf_t *clcf = conf; |
4052 | 4029 |
4053 time_t inactive; | 4030 time_t inactive; |
4054 ngx_str_t *value, s; | 4031 ngx_str_t *value, s; |
4055 ngx_int_t max; | 4032 ngx_int_t max; |
4056 ngx_uint_t i; | 4033 ngx_uint_t i; |
4057 | 4034 |
4058 if (lcf->open_file_cache != NGX_CONF_UNSET_PTR) { | 4035 if (clcf->open_file_cache != NGX_CONF_UNSET_PTR) { |
4059 return "is duplicate"; | 4036 return "is duplicate"; |
4060 } | 4037 } |
4061 | 4038 |
4062 value = cf->args->elts; | 4039 value = cf->args->elts; |
4063 | 4040 |
4089 continue; | 4066 continue; |
4090 } | 4067 } |
4091 | 4068 |
4092 if (ngx_strcmp(value[i].data, "off") == 0) { | 4069 if (ngx_strcmp(value[i].data, "off") == 0) { |
4093 | 4070 |
4094 lcf->open_file_cache = NULL; | 4071 clcf->open_file_cache = NULL; |
4095 | 4072 |
4096 continue; | 4073 continue; |
4097 } | 4074 } |
4098 | 4075 |
4099 failed: | 4076 failed: |
4102 "invalid \"open_file_cache\" parameter \"%V\"", | 4079 "invalid \"open_file_cache\" parameter \"%V\"", |
4103 &value[i]); | 4080 &value[i]); |
4104 return NGX_CONF_ERROR; | 4081 return NGX_CONF_ERROR; |
4105 } | 4082 } |
4106 | 4083 |
4107 if (lcf->open_file_cache == NULL) { | 4084 if (clcf->open_file_cache == NULL) { |
4108 return NGX_CONF_OK; | 4085 return NGX_CONF_OK; |
4109 } | 4086 } |
4110 | 4087 |
4111 if (max == 0) { | 4088 if (max == 0) { |
4112 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 4089 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
4113 "\"open_file_cache\" must have \"max\" parameter"); | 4090 "\"open_file_cache\" must have \"max\" parameter"); |
4114 return NGX_CONF_ERROR; | 4091 return NGX_CONF_ERROR; |
4115 } | 4092 } |
4116 | 4093 |
4117 lcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive); | 4094 clcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive); |
4118 if (lcf->open_file_cache) { | 4095 if (clcf->open_file_cache) { |
4119 return NGX_CONF_OK; | 4096 return NGX_CONF_OK; |
4120 } | 4097 } |
4121 | 4098 |
4122 return NGX_CONF_ERROR; | 4099 return NGX_CONF_ERROR; |
4123 } | 4100 } |
4124 | 4101 |
4125 | 4102 |
4126 static char * | 4103 static char * |
4127 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 4104 ngx_http_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
4128 { | 4105 { |
4129 ngx_http_core_loc_conf_t *lcf = conf; | 4106 ngx_http_core_loc_conf_t *clcf = conf; |
4130 | 4107 |
4131 ngx_str_t *value; | 4108 ngx_str_t *value; |
4132 | 4109 |
4133 if (lcf->error_log) { | 4110 if (clcf->error_log) { |
4134 return "is duplicate"; | 4111 return "is duplicate"; |
4135 } | 4112 } |
4136 | 4113 |
4137 value = cf->args->elts; | 4114 value = cf->args->elts; |
4138 | 4115 |
4139 lcf->error_log = ngx_log_create(cf->cycle, &value[1]); | 4116 clcf->error_log = ngx_log_create(cf->cycle, &value[1]); |
4140 if (lcf->error_log == NULL) { | 4117 if (clcf->error_log == NULL) { |
4141 return NGX_CONF_ERROR; | 4118 return NGX_CONF_ERROR; |
4142 } | 4119 } |
4143 | 4120 |
4144 if (cf->args->nelts == 2) { | 4121 if (cf->args->nelts == 2) { |
4145 lcf->error_log->log_level = NGX_LOG_ERR; | 4122 clcf->error_log->log_level = NGX_LOG_ERR; |
4146 return NGX_CONF_OK; | 4123 return NGX_CONF_OK; |
4147 } | 4124 } |
4148 | 4125 |
4149 return ngx_log_set_levels(cf, lcf->error_log); | 4126 return ngx_log_set_levels(cf, clcf->error_log); |
4150 } | 4127 } |
4151 | 4128 |
4152 | 4129 |
4153 static char * | 4130 static char * |
4154 ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 4131 ngx_http_core_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
4155 { | 4132 { |
4156 ngx_http_core_loc_conf_t *lcf = conf; | 4133 ngx_http_core_loc_conf_t *clcf = conf; |
4157 | 4134 |
4158 ngx_str_t *value; | 4135 ngx_str_t *value; |
4159 | 4136 |
4160 if (lcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) { | 4137 if (clcf->keepalive_timeout != NGX_CONF_UNSET_MSEC) { |
4161 return "is duplicate"; | 4138 return "is duplicate"; |
4162 } | 4139 } |
4163 | 4140 |
4164 value = cf->args->elts; | 4141 value = cf->args->elts; |
4165 | 4142 |
4166 lcf->keepalive_timeout = ngx_parse_time(&value[1], 0); | 4143 clcf->keepalive_timeout = ngx_parse_time(&value[1], 0); |
4167 | 4144 |
4168 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) { | 4145 if (clcf->keepalive_timeout == (ngx_msec_t) NGX_ERROR) { |
4169 return "invalid value"; | 4146 return "invalid value"; |
4170 } | 4147 } |
4171 | 4148 |
4172 if (lcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) { | 4149 if (clcf->keepalive_timeout == (ngx_msec_t) NGX_PARSE_LARGE_TIME) { |
4173 return "value must be less than 597 hours"; | 4150 return "value must be less than 597 hours"; |
4174 } | 4151 } |
4175 | 4152 |
4176 if (cf->args->nelts == 2) { | 4153 if (cf->args->nelts == 2) { |
4177 return NGX_CONF_OK; | 4154 return NGX_CONF_OK; |
4178 } | 4155 } |
4179 | 4156 |
4180 lcf->keepalive_header = ngx_parse_time(&value[2], 1); | 4157 clcf->keepalive_header = ngx_parse_time(&value[2], 1); |
4181 | 4158 |
4182 if (lcf->keepalive_header == NGX_ERROR) { | 4159 if (clcf->keepalive_header == NGX_ERROR) { |
4183 return "invalid value"; | 4160 return "invalid value"; |
4184 } | 4161 } |
4185 | 4162 |
4186 if (lcf->keepalive_header == NGX_PARSE_LARGE_TIME) { | 4163 if (clcf->keepalive_header == NGX_PARSE_LARGE_TIME) { |
4187 return "value must be less than 68 years"; | 4164 return "value must be less than 68 years"; |
4188 } | 4165 } |
4189 | 4166 |
4190 return NGX_CONF_OK; | 4167 return NGX_CONF_OK; |
4191 } | 4168 } |
4192 | 4169 |
4193 | 4170 |
4194 static char * | 4171 static char * |
4195 ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 4172 ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
4196 { | 4173 { |
4197 ngx_http_core_loc_conf_t *lcf = conf; | 4174 ngx_http_core_loc_conf_t *clcf = conf; |
4198 | 4175 |
4199 if (lcf->internal != NGX_CONF_UNSET) { | 4176 if (clcf->internal != NGX_CONF_UNSET) { |
4200 return "is duplicate"; | 4177 return "is duplicate"; |
4201 } | 4178 } |
4202 | 4179 |
4203 lcf->internal = 1; | 4180 clcf->internal = 1; |
4204 | 4181 |
4205 return NGX_CONF_OK; | 4182 return NGX_CONF_OK; |
4206 } | 4183 } |
4207 | 4184 |
4208 | 4185 |
4246 { | 4223 { |
4247 ngx_http_core_loc_conf_t *clcf = conf; | 4224 ngx_http_core_loc_conf_t *clcf = conf; |
4248 | 4225 |
4249 #if (NGX_PCRE) | 4226 #if (NGX_PCRE) |
4250 | 4227 |
4251 ngx_str_t err, *value; | 4228 ngx_str_t *value; |
4252 ngx_uint_t i; | 4229 ngx_uint_t i; |
4253 ngx_regex_elt_t *re; | 4230 ngx_regex_elt_t *re; |
4254 u_char errstr[NGX_MAX_CONF_ERRSTR]; | 4231 ngx_regex_compile_t rc; |
4232 u_char errstr[NGX_MAX_CONF_ERRSTR]; | |
4255 | 4233 |
4256 if (clcf->gzip_disable == NGX_CONF_UNSET_PTR) { | 4234 if (clcf->gzip_disable == NGX_CONF_UNSET_PTR) { |
4257 clcf->gzip_disable = ngx_array_create(cf->pool, 2, | 4235 clcf->gzip_disable = ngx_array_create(cf->pool, 2, |
4258 sizeof(ngx_regex_elt_t)); | 4236 sizeof(ngx_regex_elt_t)); |
4259 if (clcf->gzip_disable == NULL) { | 4237 if (clcf->gzip_disable == NULL) { |
4261 } | 4239 } |
4262 } | 4240 } |
4263 | 4241 |
4264 value = cf->args->elts; | 4242 value = cf->args->elts; |
4265 | 4243 |
4266 err.len = NGX_MAX_CONF_ERRSTR; | 4244 ngx_memzero(&rc, sizeof(ngx_regex_compile_t)); |
4267 err.data = errstr; | 4245 |
4246 rc.pool = cf->pool; | |
4247 rc.err.len = NGX_MAX_CONF_ERRSTR; | |
4248 rc.err.data = errstr; | |
4268 | 4249 |
4269 for (i = 1; i < cf->args->nelts; i++) { | 4250 for (i = 1; i < cf->args->nelts; i++) { |
4270 | 4251 |
4271 if (ngx_strcmp(value[1].data, "msie6") == 0) { | 4252 if (ngx_strcmp(value[1].data, "msie6") == 0) { |
4272 clcf->gzip_disable_msie6 = 1; | 4253 clcf->gzip_disable_msie6 = 1; |
4276 re = ngx_array_push(clcf->gzip_disable); | 4257 re = ngx_array_push(clcf->gzip_disable); |
4277 if (re == NULL) { | 4258 if (re == NULL) { |
4278 return NGX_CONF_ERROR; | 4259 return NGX_CONF_ERROR; |
4279 } | 4260 } |
4280 | 4261 |
4281 re->regex = ngx_regex_compile(&value[i], NGX_REGEX_CASELESS, cf->pool, | 4262 rc.pattern = value[1]; |
4282 &err); | 4263 rc.options = NGX_REGEX_CASELESS; |
4283 | 4264 |
4284 if (re->regex == NULL) { | 4265 if (ngx_regex_compile(&rc) != NGX_OK) { |
4285 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data); | 4266 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err); |
4286 return NGX_CONF_ERROR; | 4267 return NGX_CONF_ERROR; |
4287 } | 4268 } |
4288 | 4269 |
4270 re->regex = rc.regex; | |
4289 re->name = value[i].data; | 4271 re->name = value[i].data; |
4290 } | 4272 } |
4291 | 4273 |
4292 return NGX_CONF_OK; | 4274 return NGX_CONF_OK; |
4293 | 4275 |
4346 { | 4328 { |
4347 size_t *sp = data; | 4329 size_t *sp = data; |
4348 | 4330 |
4349 if (*sp < NGX_MIN_POOL_SIZE) { | 4331 if (*sp < NGX_MIN_POOL_SIZE) { |
4350 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 4332 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
4351 "pool must be no less than %uz", NGX_MIN_POOL_SIZE); | 4333 "the pool size must be no less than %uz", |
4352 | 4334 NGX_MIN_POOL_SIZE); |
4353 return NGX_CONF_ERROR; | 4335 return NGX_CONF_ERROR; |
4354 } | 4336 } |
4355 | 4337 |
4338 if (*sp % NGX_POOL_ALIGNMENT) { | |
4339 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
4340 "the pool size must be a multiple of %uz", | |
4341 NGX_POOL_ALIGNMENT); | |
4342 return NGX_CONF_ERROR; | |
4343 } | |
4344 | |
4356 return NGX_CONF_OK; | 4345 return NGX_CONF_OK; |
4357 } | 4346 } |