comparison src/http/ngx_http_core_module.c @ 72:b31656313b59 NGINX_0_1_36

nginx 0.1.36 *) Change: if the request header has duplicate the "Host", "Connection", "Content-Length", or "Authorization" lines, then nginx now returns the 400 error. *) Change: the "post_accept_timeout" directive was canceled. *) Feature: the "default", "af=", "bl=", "deferred", and "bind" parameters of the "listen" directive. *) Feature: the FreeBSD accept filters support. *) Feature: the Linux TCP_DEFER_ACCEPT support. *) Bugfix: the ngx_http_autoindex_module did not support the file names in UTF-8. *) Bugfix: the new log file can be rotated by the -USR1 signal only if the reconfiguration by the -HUP signal was made twice.
author Igor Sysoev <http://sysoev.ru>
date Wed, 15 Jun 2005 00:00:00 +0400
parents 8ad297c88dcb
children da9a3b14312d
comparison
equal deleted inserted replaced
71:66f1f40f29d6 72:b31656313b59
100 ngx_conf_set_size_slot, 100 ngx_conf_set_size_slot,
101 NGX_HTTP_SRV_CONF_OFFSET, 101 NGX_HTTP_SRV_CONF_OFFSET,
102 offsetof(ngx_http_core_srv_conf_t, connection_pool_size), 102 offsetof(ngx_http_core_srv_conf_t, connection_pool_size),
103 NULL }, 103 NULL },
104 104
105 { ngx_string("post_accept_timeout"),
106 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
107 ngx_conf_set_msec_slot,
108 NGX_HTTP_SRV_CONF_OFFSET,
109 offsetof(ngx_http_core_srv_conf_t, post_accept_timeout),
110 NULL },
111
112 { ngx_string("request_pool_size"), 105 { ngx_string("request_pool_size"),
113 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, 106 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
114 ngx_conf_set_size_slot, 107 ngx_conf_set_size_slot,
115 NGX_HTTP_SRV_CONF_OFFSET, 108 NGX_HTTP_SRV_CONF_OFFSET,
116 offsetof(ngx_http_core_srv_conf_t, request_pool_size), 109 offsetof(ngx_http_core_srv_conf_t, request_pool_size),
158 0, 151 0,
159 NULL }, 152 NULL },
160 153
161 { ngx_string("listen"), 154 { ngx_string("listen"),
162 #if 0 155 #if 0
163 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, 156 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
164 #else 157 #else
165 NGX_HTTP_SRV_CONF|NGX_CONF_TAKE12, 158 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
166 #endif 159 #endif
167 ngx_http_core_listen, 160 ngx_http_core_listen,
168 NGX_HTTP_SRV_CONF_OFFSET, 161 NGX_HTTP_SRV_CONF_OFFSET,
169 0, 162 0,
170 NULL }, 163 NULL },
1590 { 1583 {
1591 return NGX_CONF_ERROR; 1584 return NGX_CONF_ERROR;
1592 } 1585 }
1593 1586
1594 cscf->connection_pool_size = NGX_CONF_UNSET_SIZE; 1587 cscf->connection_pool_size = NGX_CONF_UNSET_SIZE;
1595 cscf->post_accept_timeout = NGX_CONF_UNSET_MSEC;
1596 cscf->request_pool_size = NGX_CONF_UNSET_SIZE; 1588 cscf->request_pool_size = NGX_CONF_UNSET_SIZE;
1597 cscf->client_header_timeout = NGX_CONF_UNSET_MSEC; 1589 cscf->client_header_timeout = NGX_CONF_UNSET_MSEC;
1598 cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE; 1590 cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE;
1599 cscf->restrict_host_names = NGX_CONF_UNSET_UINT; 1591 cscf->restrict_host_names = NGX_CONF_UNSET_UINT;
1600 cscf->ignore_invalid_headers = NGX_CONF_UNSET; 1592 cscf->ignore_invalid_headers = NGX_CONF_UNSET;
1618 if (conf->listen.nelts == 0) { 1610 if (conf->listen.nelts == 0) {
1619 ls = ngx_array_push(&conf->listen); 1611 ls = ngx_array_push(&conf->listen);
1620 if (ls == NULL) { 1612 if (ls == NULL) {
1621 return NGX_CONF_ERROR; 1613 return NGX_CONF_ERROR;
1622 } 1614 }
1615
1616 ngx_memzero(ls, sizeof(ngx_http_listen_t));
1623 1617
1624 ls->addr = INADDR_ANY; 1618 ls->addr = INADDR_ANY;
1625 #if (NGX_WIN32) 1619 #if (NGX_WIN32)
1626 ls->port = 80; 1620 ls->port = 80;
1627 #else 1621 #else
1628 /* STUB: getuid() should be cached */ 1622 /* STUB: getuid() should be cached */
1629 ls->port = (getuid() == 0) ? 80 : 8000; 1623 ls->port = (getuid() == 0) ? 80 : 8000;
1630 #endif 1624 #endif
1631 ls->family = AF_INET; 1625 ls->family = AF_INET;
1632 ls->default_server = 0;
1633 } 1626 }
1634 1627
1635 if (conf->server_names.nelts == 0) { 1628 if (conf->server_names.nelts == 0) {
1636 sn = ngx_array_push(&conf->server_names); 1629 sn = ngx_array_push(&conf->server_names);
1637 if (sn == NULL) { 1630 if (sn == NULL) {
1660 } 1653 }
1661 } 1654 }
1662 1655
1663 ngx_conf_merge_size_value(conf->connection_pool_size, 1656 ngx_conf_merge_size_value(conf->connection_pool_size,
1664 prev->connection_pool_size, 256); 1657 prev->connection_pool_size, 256);
1665 ngx_conf_merge_msec_value(conf->post_accept_timeout,
1666 prev->post_accept_timeout, 60000);
1667 ngx_conf_merge_size_value(conf->request_pool_size, 1658 ngx_conf_merge_size_value(conf->request_pool_size,
1668 prev->request_pool_size, 4096); 1659 prev->request_pool_size, 4096);
1669 ngx_conf_merge_msec_value(conf->client_header_timeout, 1660 ngx_conf_merge_msec_value(conf->client_header_timeout,
1670 prev->client_header_timeout, 60000); 1661 prev->client_header_timeout, 60000);
1671 ngx_conf_merge_size_value(conf->client_header_buffer_size, 1662 ngx_conf_merge_size_value(conf->client_header_buffer_size,
1857 1848
1858 return NGX_CONF_OK; 1849 return NGX_CONF_OK;
1859 } 1850 }
1860 1851
1861 1852
1853 /* AF_INET only */
1854
1862 static char * 1855 static char *
1863 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 1856 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1864 { 1857 {
1865 ngx_http_core_srv_conf_t *scf = conf; 1858 ngx_http_core_srv_conf_t *scf = conf;
1866 1859
1867 u_char *addr; 1860 char *err;
1868 ngx_int_t port; 1861 ngx_str_t *value;
1869 ngx_uint_t p; 1862 ngx_uint_t n;
1870 ngx_str_t *args; 1863 struct hostent *h;
1871 struct hostent *h; 1864 ngx_http_listen_t *ls;
1872 ngx_http_listen_t *ls; 1865 ngx_inet_upstream_t inet_upstream;
1873 1866
1874 /* 1867 /*
1875 * TODO: check duplicate 'listen' directives, 1868 * TODO: check duplicate 'listen' directives,
1876 * add resolved name to server names ??? 1869 * add resolved name to server names ???
1877 */ 1870 */
1878 1871
1872 value = cf->args->elts;
1873
1874 ngx_memzero(&inet_upstream, sizeof(ngx_inet_upstream_t));
1875
1876 inet_upstream.url = value[1];
1877 inet_upstream.port_only = 1;
1878
1879 err = ngx_inet_parse_host_port(&inet_upstream);
1880
1881 if (err) {
1882 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1883 "%s in \"%V\" of the \"listen\" directive",
1884 err, &inet_upstream.url);
1885 return NGX_CONF_ERROR;
1886 }
1887
1879 ls = ngx_array_push(&scf->listen); 1888 ls = ngx_array_push(&scf->listen);
1880 if (ls == NULL) { 1889 if (ls == NULL) {
1881 return NGX_CONF_ERROR; 1890 return NGX_CONF_ERROR;
1882 } 1891 }
1883 1892
1884 /* AF_INET only */ 1893 ngx_memzero(ls, sizeof(ngx_http_listen_t));
1885 1894
1886 ls->family = AF_INET; 1895 ls->family = AF_INET;
1896 ls->port = (in_port_t) (inet_upstream.default_port ?
1897 80 : inet_upstream.port);
1887 ls->file_name = cf->conf_file->file.name; 1898 ls->file_name = cf->conf_file->file.name;
1888 ls->line = cf->conf_file->line; 1899 ls->line = cf->conf_file->line;
1889 ls->default_server = 0; 1900 ls->conf.backlog = -1;
1890 1901
1891 args = cf->args->elts; 1902 if (inet_upstream.host.len) {
1892 addr = args[1].data; 1903 inet_upstream.host.data[inet_upstream.host.len] = '\0';
1893 1904
1894 for (p = 0; p < args[1].len; p++) { 1905 ls->addr = inet_addr((const char *) inet_upstream.host.data);
1895 if (addr[p] == ':') { 1906
1896 addr[p++] = '\0'; 1907 if (ls->addr == INADDR_NONE) {
1897 break; 1908 h = gethostbyname((const char *) inet_upstream.host.data);
1898 } 1909
1899 } 1910 if (h == NULL || h->h_addr_list[0] == NULL) {
1900 1911 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1901 if (p == args[1].len) { 1912 "can not resolve host \"%s\" "
1902 /* no ":" in the "listen" */ 1913 "in the \"listen\" directive",
1903 p = 0; 1914 inet_upstream.host.data);
1904 } 1915 return NGX_CONF_ERROR;
1905 1916 }
1906 port = ngx_atoi(&addr[p], args[1].len - p); 1917
1907 1918 ls->addr = *(in_addr_t *)(h->h_addr_list[0]);
1908 if (port == NGX_ERROR && p == 0) { 1919 }
1909 1920
1910 /* "listen host" */ 1921 } else {
1911 ls->port = 80; 1922 ls->addr = INADDR_ANY;
1912 1923 }
1913 } else if ((port == NGX_ERROR && p != 0) /* "listen host:NONNUMBER" */ 1924
1914 || (port < 1 || port > 65536)) { /* "listen 99999" */ 1925 if (cf->args->nelts == 2) {
1926 return NGX_CONF_OK;
1927 }
1928
1929 if (ngx_strcmp(value[2].data, "default") == 0) {
1930 ls->conf.default_server = 1;
1931 n = 3;
1932 } else {
1933 n = 2;
1934 }
1935
1936 for ( /* void */ ; n < cf->args->nelts; n++) {
1937
1938 if (ls->conf.default_server == 0) {
1939 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1940 "\"%V\" parameter can be specified for "
1941 "the default \"listen\" directive only",
1942 &value[n]);
1943 return NGX_CONF_ERROR;
1944 }
1945
1946 if (ngx_strcmp(value[n].data, "bind") == 0) {
1947 ls->conf.bind = 1;
1948 continue;
1949 }
1950
1951 if (ngx_strncmp(value[n].data, "bl=", 3) == 0) {
1952 ls->conf.backlog = ngx_atoi(value[n].data + 3, value[n].len - 3);
1953 ls->conf.bind = 1;
1954
1955 if (ls->conf.backlog == NGX_ERROR || ls->conf.backlog == 0) {
1956 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1957 "invalid backlog \"%V\"", &value[n]);
1958 return NGX_CONF_ERROR;
1959 }
1960
1961 continue;
1962 }
1963
1964 if (ngx_strncmp(value[n].data, "af=", 3) == 0) {
1965 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
1966 ls->conf.accept_filter = (char *) &value[n].data[3];
1967 ls->conf.bind = 1;
1968 #else
1969 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1970 "accept filters \"%V\" are not supported "
1971 "on this platform, ignored",
1972 &value[n]);
1973 #endif
1974 continue;
1975 }
1976
1977 if (ngx_strcmp(value[n].data, "deferred") == 0) {
1978 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
1979 ls->conf.deferred_accept = 1;
1980 ls->conf.bind = 1;
1981 #else
1982 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1983 "the deferred accept is not supported "
1984 "on this platform, ignored");
1985 #endif
1986 continue;
1987 }
1915 1988
1916 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 1989 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1917 "invalid port \"%s\" in \"%V\" directive, " 1990 "the invalid \"%V\" parameter", &value[n]);
1918 "it must be a number between 1 and 65535",
1919 &addr[p], &cmd->name);
1920
1921 return NGX_CONF_ERROR; 1991 return NGX_CONF_ERROR;
1922
1923 } else if (p == 0) {
1924 ls->addr = INADDR_ANY;
1925 ls->port = (in_port_t) port;
1926 return NGX_CONF_OK;
1927
1928 } else {
1929 ls->port = (in_port_t) port;
1930 }
1931
1932 ls->addr = inet_addr((const char *) addr);
1933
1934 if (ls->addr == INADDR_NONE) {
1935 h = gethostbyname((const char *) addr);
1936
1937 if (h == NULL || h->h_addr_list[0] == NULL) {
1938 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1939 "can not resolve host \"%s\" "
1940 "in \"%V\" directive", addr, &cmd->name);
1941 return NGX_CONF_ERROR;
1942 }
1943
1944 ls->addr = *(in_addr_t *)(h->h_addr_list[0]);
1945 } 1992 }
1946 1993
1947 return NGX_CONF_OK; 1994 return NGX_CONF_OK;
1948 } 1995 }
1949 1996