comparison src/http/ngx_http_core_module.c @ 324:f7cd062ee035 NGINX_0_6_6

nginx 0.6.6 *) Feature: the --sysconfdir=PATH option in configure. *) Feature: named locations. *) Feature: the $args variable can be set with the "set" directive. *) Feature: the $is_args variable. *) Bugfix: fair big weight upstream balancer. *) Bugfix: if a client has closed connection to mail proxy then nginx might not close connection to backend. *) Bugfix: if the same host without specified port was used as backend for HTTP and HTTPS, then nginx used only one port - 80 or 443. *) Bugfix: fix building on Solaris/amd64 by Sun Studio 11 and early versions; bug appeared in 0.6.4.
author Igor Sysoev <http://sysoev.ru>
date Mon, 30 Jul 2007 00:00:00 +0400
parents 429900ca25ee
children 9fc4ab6673f9
comparison
equal deleted inserted replaced
323:7e977a664d91 324:f7cd062ee035
943 noregex = 0; 943 noregex = 0;
944 944
945 clcfp = locations->elts; 945 clcfp = locations->elts;
946 for (i = 0; i < locations->nelts; i++) { 946 for (i = 0; i < locations->nelts; i++) {
947 947
948 if (clcfp[i]->noname
948 #if (NGX_PCRE) 949 #if (NGX_PCRE)
949 if (clcfp[i]->regex) { 950 || clcfp[i]->regex
950 break;
951 }
952 #endif 951 #endif
953 952 || clcfp[i]->named)
954 if (clcfp[i]->noname) { 953 {
955 break; 954 break;
956 } 955 }
957 956
958 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 957 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
959 "find location: %s\"%V\"", 958 "find location: %s\"%V\"",
1026 1025
1027 /* regex matches */ 1026 /* regex matches */
1028 1027
1029 for (i = regex_start; i < locations->nelts; i++) { 1028 for (i = regex_start; i < locations->nelts; i++) {
1030 1029
1031 if (clcfp[i]->noname) { 1030 if (!clcfp[i]->regex) {
1032 break; 1031 break;
1033 } 1032 }
1034 1033
1035 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 1034 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1036 "find location: ~ \"%V\"", &clcfp[i]->name); 1035 "find location: ~ \"%V\"", &clcfp[i]->name);
1221 == NULL) 1220 == NULL)
1222 { 1221 {
1223 return NULL; 1222 return NULL;
1224 } 1223 }
1225 1224
1226 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path) == NGX_ERROR) { 1225 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, path, 0)== NGX_ERROR)
1226 {
1227 return NULL; 1227 return NULL;
1228 } 1228 }
1229 1229
1230 *root_length = path->len - reserved; 1230 *root_length = path->len - reserved;
1231 last = path->data + *root_length; 1231 last = path->data + *root_length;
1511 1511
1512 return NGX_DONE; 1512 return NGX_DONE;
1513 } 1513 }
1514 1514
1515 1515
1516 ngx_int_t
1517 ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name)
1518 {
1519 ngx_uint_t i;
1520 ngx_http_core_srv_conf_t *cscf;
1521 ngx_http_core_loc_conf_t **clcfp;
1522 ngx_http_core_main_conf_t *cmcf;
1523
1524 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
1525
1526 clcfp = cscf->locations.elts;
1527
1528 for (i = cscf->named_start; i < cscf->locations.nelts; i++) {
1529
1530 if (name->len != clcfp[i]->name.len
1531 || ngx_strncmp(name->data, clcfp[i]->name.data, name->len) != 0)
1532 {
1533 continue;
1534 }
1535
1536 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1537 "named location: %V \"%V?%V\"", name, &r->uri, &r->args);
1538
1539 r->internal = 1;
1540
1541 r->loc_conf = clcfp[i]->loc_conf;
1542
1543 ngx_http_update_location_config(r);
1544
1545 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
1546
1547 r->phase_handler = cmcf->phase_engine.location_rewrite_index;
1548 ngx_http_core_run_phases(r);
1549
1550 return NGX_DONE;
1551 }
1552
1553 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1554 "could not find name location \"%V\"", name);
1555
1556 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1557 return NGX_DONE;
1558 }
1559
1560
1516 ngx_http_cleanup_t * 1561 ngx_http_cleanup_t *
1517 ngx_http_cleanup_add(ngx_http_request_t *r, size_t size) 1562 ngx_http_cleanup_add(ngx_http_request_t *r, size_t size)
1518 { 1563 {
1519 ngx_http_cleanup_t *cln; 1564 ngx_http_cleanup_t *cln;
1520 1565
1555 ngx_uint_t i; 1600 ngx_uint_t i;
1556 ngx_conf_t pcf; 1601 ngx_conf_t pcf;
1557 ngx_http_module_t *module; 1602 ngx_http_module_t *module;
1558 ngx_http_conf_ctx_t *ctx, *http_ctx; 1603 ngx_http_conf_ctx_t *ctx, *http_ctx;
1559 ngx_http_core_srv_conf_t *cscf, **cscfp; 1604 ngx_http_core_srv_conf_t *cscf, **cscfp;
1605 ngx_http_core_loc_conf_t **clcfp;
1560 ngx_http_core_main_conf_t *cmcf; 1606 ngx_http_core_main_conf_t *cmcf;
1561 #if (NGX_PCRE)
1562 ngx_http_core_loc_conf_t **clcfp;
1563 #endif
1564 1607
1565 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); 1608 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
1566 if (ctx == NULL) { 1609 if (ctx == NULL) {
1567 return NGX_CONF_ERROR; 1610 return NGX_CONF_ERROR;
1568 } 1611 }
1642 } 1685 }
1643 1686
1644 ngx_sort(cscf->locations.elts, (size_t) cscf->locations.nelts, 1687 ngx_sort(cscf->locations.elts, (size_t) cscf->locations.nelts,
1645 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations); 1688 sizeof(ngx_http_core_loc_conf_t *), ngx_http_core_cmp_locations);
1646 1689
1690 clcfp = cscf->locations.elts;
1691
1647 #if (NGX_PCRE) 1692 #if (NGX_PCRE)
1648 1693
1649 cscf->regex_start = cscf->locations.nelts; 1694 cscf->regex_start = cscf->locations.nelts;
1650 clcfp = cscf->locations.elts;
1651 1695
1652 for (i = 0; i < cscf->locations.nelts; i++) { 1696 for (i = 0; i < cscf->locations.nelts; i++) {
1653 if (clcfp[i]->regex) { 1697 if (clcfp[i]->regex) {
1654 cscf->regex_start = i; 1698 cscf->regex_start = i;
1655 break; 1699 break;
1656 } 1700 }
1657 } 1701 }
1658 1702
1659 #endif 1703 #endif
1704
1705 cscf->named_start = cscf->locations.nelts;
1706
1707 for (i = 0; i < cscf->locations.nelts; i++) {
1708 if (clcfp[i]->named) {
1709 cscf->named_start = i;
1710 break;
1711 }
1712 }
1660 1713
1661 return rv; 1714 return rv;
1662 } 1715 }
1663 1716
1664 1717
1756 "invalid location modifier \"%V\"", &value[1]); 1809 "invalid location modifier \"%V\"", &value[1]);
1757 return NGX_CONF_ERROR; 1810 return NGX_CONF_ERROR;
1758 } 1811 }
1759 1812
1760 } else { 1813 } else {
1814
1761 clcf->name = value[1]; 1815 clcf->name = value[1];
1816
1817 if (value[1].data[0] == '@') {
1818 clcf->named = 1;
1819 }
1762 } 1820 }
1763 1821
1764 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index]; 1822 pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
1765 1823
1766 if (pclcf->name.len == 0) { 1824 if (pclcf->name.len == 0) {
1778 1836
1779 if (pclcf->exact_match) { 1837 if (pclcf->exact_match) {
1780 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 1838 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1781 "location \"%V\" could not be inside " 1839 "location \"%V\" could not be inside "
1782 "the exact location \"%V\"", 1840 "the exact location \"%V\"",
1841 &clcf->name, &pclcf->name);
1842 return NGX_CONF_ERROR;
1843 }
1844
1845 if (pclcf->named) {
1846 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1847 "location \"%V\" could not be inside "
1848 "the named location \"%V\"",
1783 &clcf->name, &pclcf->name); 1849 &clcf->name, &pclcf->name);
1784 return NGX_CONF_ERROR; 1850 return NGX_CONF_ERROR;
1785 } 1851 }
1786 1852
1787 #if (NGX_PCRE) 1853 #if (NGX_PCRE)
1859 ngx_http_core_loc_conf_t *first, *second; 1925 ngx_http_core_loc_conf_t *first, *second;
1860 1926
1861 first = *(ngx_http_core_loc_conf_t **) one; 1927 first = *(ngx_http_core_loc_conf_t **) one;
1862 second = *(ngx_http_core_loc_conf_t **) two; 1928 second = *(ngx_http_core_loc_conf_t **) two;
1863 1929
1930 if (first->named && !second->named) {
1931 /* shift named locations to the end */
1932 return 1;
1933 }
1934
1935 if (!first->named && second->named) {
1936 /* shift named locations to the end */
1937 return -1;
1938 }
1939
1940 if (first->named && second->named) {
1941 return ngx_strcmp(first->name.data, second->name.data);
1942 }
1943
1864 if (first->noname && !second->noname) { 1944 if (first->noname && !second->noname) {
1865 /* shift no named locations to the end */ 1945 /* shift no named locations to the end */
1866 return 1; 1946 return 1;
1867 } 1947 }
1868 1948
1945 value = cf->args->elts; 2025 value = cf->args->elts;
1946 2026
1947 if (ngx_strcmp(value[0].data, "include") == 0) { 2027 if (ngx_strcmp(value[0].data, "include") == 0) {
1948 file = value[1]; 2028 file = value[1];
1949 2029
1950 if (ngx_conf_full_name(cf->cycle, &file) == NGX_ERROR){ 2030 if (ngx_conf_full_name(cf->cycle, &file, 1) == NGX_ERROR){
1951 return NGX_CONF_ERROR; 2031 return NGX_CONF_ERROR;
1952 } 2032 }
1953 2033
1954 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data); 2034 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
1955 2035
2288 2368
2289 if (prev->root.data == NULL) { 2369 if (prev->root.data == NULL) {
2290 conf->root.len = sizeof("html") - 1; 2370 conf->root.len = sizeof("html") - 1;
2291 conf->root.data = (u_char *) "html"; 2371 conf->root.data = (u_char *) "html";
2292 2372
2293 if (ngx_conf_full_name(cf->cycle, &conf->root) == NGX_ERROR) { 2373 if (ngx_conf_full_name(cf->cycle, &conf->root, 0) == NGX_ERROR) {
2294 return NGX_CONF_ERROR; 2374 return NGX_CONF_ERROR;
2295 } 2375 }
2296 } 2376 }
2297 } 2377 }
2298 2378
2704 } 2784 }
2705 2785
2706 return NGX_CONF_ERROR; 2786 return NGX_CONF_ERROR;
2707 } 2787 }
2708 2788
2789 if (lcf->named && alias) {
2790 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2791 "the \"alias\" directive may not be used "
2792 "inside named location");
2793
2794 return NGX_CONF_ERROR;
2795 }
2796
2709 #if (NGX_PCRE) 2797 #if (NGX_PCRE)
2710 2798
2711 if (lcf->regex && alias) { 2799 if (lcf->regex && alias) {
2712 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 2800 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2713 "the \"alias\" directive may not be used " 2801 "the \"alias\" directive may not be used "
2737 if (!alias && lcf->root.data[lcf->root.len - 1] == '/') { 2825 if (!alias && lcf->root.data[lcf->root.len - 1] == '/') {
2738 lcf->root.len--; 2826 lcf->root.len--;
2739 } 2827 }
2740 2828
2741 if (lcf->root.data[0] != '$') { 2829 if (lcf->root.data[0] != '$') {
2742 if (ngx_conf_full_name(cf->cycle, &lcf->root) == NGX_ERROR) { 2830 if (ngx_conf_full_name(cf->cycle, &lcf->root, 0) == NGX_ERROR) {
2743 return NGX_CONF_ERROR; 2831 return NGX_CONF_ERROR;
2744 } 2832 }
2745 } 2833 }
2746 2834
2747 n = ngx_http_script_variables_count(&lcf->root); 2835 n = ngx_http_script_variables_count(&lcf->root);