Mercurial > hg > nginx-vendor-0-5
comparison src/http/ngx_http_core_module.c @ 142:84910468f6de NGINX_0_3_18
nginx 0.3.18
*) Feature: the "server_names" directive supports the ".domain.tld"
names.
*) Feature: the "server_names" directive uses the hash for the
"*.domain.tld" names and more effective hash for usual names.
*) Change: the "server_names_hash_max_size" and
"server_names_hash_bucket_size" directives.
*) Change: the "server_names_hash" and "server_names_hash_threshold"
directives were canceled.
*) Feature: the "valid_referers" directive uses the hash site names.
*) Change: now the "valid_referers" directive checks the site names
only without the URI part.
*) Bugfix: some ".domain.tld" names incorrectly processed by the
ngx_http_map_module.
*) Bugfix: segmentation fault was occurred if configuration file did
not exist; bug appeared in 0.3.12.
*) Bugfix: on 64-bit platforms segmentation fault may occurred on
start; bug appeared in 0.3.16.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 26 Dec 2005 00:00:00 +0300 |
parents | 8e6d4d96ec4c |
children | e1c6ac408b68 |
comparison
equal
deleted
inserted
replaced
141:249e67502bf3 | 142:84910468f6de |
---|---|
71 }; | 71 }; |
72 | 72 |
73 | 73 |
74 static ngx_command_t ngx_http_core_commands[] = { | 74 static ngx_command_t ngx_http_core_commands[] = { |
75 | 75 |
76 { ngx_string("server_names_hash"), | 76 { ngx_string("server_names_hash_max_size"), |
77 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, | 77 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, |
78 ngx_conf_set_num_slot, | 78 ngx_conf_set_num_slot, |
79 NGX_HTTP_MAIN_CONF_OFFSET, | 79 NGX_HTTP_MAIN_CONF_OFFSET, |
80 offsetof(ngx_http_core_main_conf_t, server_names_hash), | 80 offsetof(ngx_http_core_main_conf_t, server_names_hash_max_size), |
81 NULL }, | 81 NULL }, |
82 | 82 |
83 { ngx_string("server_names_hash_threshold"), | 83 { ngx_string("server_names_hash_bucket_size"), |
84 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, | 84 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, |
85 ngx_conf_set_num_slot, | 85 ngx_conf_set_num_slot, |
86 NGX_HTTP_MAIN_CONF_OFFSET, | 86 NGX_HTTP_MAIN_CONF_OFFSET, |
87 offsetof(ngx_http_core_main_conf_t, server_names_hash_threshold), | 87 offsetof(ngx_http_core_main_conf_t, server_names_hash_bucket_size), |
88 NULL }, | 88 NULL }, |
89 | 89 |
90 { ngx_string("server"), | 90 { ngx_string("server"), |
91 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, | 91 NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, |
92 ngx_http_core_server, | 92 ngx_http_core_server, |
1713 == NGX_ERROR) | 1713 == NGX_ERROR) |
1714 { | 1714 { |
1715 return NGX_CONF_ERROR; | 1715 return NGX_CONF_ERROR; |
1716 } | 1716 } |
1717 | 1717 |
1718 cmcf->server_names_hash = NGX_CONF_UNSET_UINT; | 1718 cmcf->server_names_hash_max_size = NGX_CONF_UNSET_UINT; |
1719 cmcf->server_names_hash_threshold = NGX_CONF_UNSET_UINT; | 1719 cmcf->server_names_hash_bucket_size = NGX_CONF_UNSET_UINT; |
1720 | 1720 |
1721 return cmcf; | 1721 return cmcf; |
1722 } | 1722 } |
1723 | 1723 |
1724 | 1724 |
1725 static char * | 1725 static char * |
1726 ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf) | 1726 ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf) |
1727 { | 1727 { |
1728 ngx_http_core_main_conf_t *cmcf = conf; | 1728 ngx_http_core_main_conf_t *cmcf = conf; |
1729 | 1729 |
1730 if (cmcf->server_names_hash == NGX_CONF_UNSET_UINT) { | 1730 if (cmcf->server_names_hash_max_size == NGX_CONF_UNSET_UINT) { |
1731 cmcf->server_names_hash = 1009; | 1731 cmcf->server_names_hash_max_size = 512; |
1732 } | 1732 } |
1733 | 1733 |
1734 if (cmcf->server_names_hash_threshold == NGX_CONF_UNSET_UINT) { | 1734 if (cmcf->server_names_hash_bucket_size == NGX_CONF_UNSET_UINT) { |
1735 cmcf->server_names_hash_threshold = 50; | 1735 cmcf->server_names_hash_bucket_size = ngx_cacheline_size; |
1736 } | 1736 } |
1737 | |
1738 cmcf->server_names_hash_bucket_size = | |
1739 ngx_align(cmcf->server_names_hash_bucket_size, ngx_cacheline_size); | |
1737 | 1740 |
1738 return NGX_CONF_OK; | 1741 return NGX_CONF_OK; |
1739 } | 1742 } |
1740 | 1743 |
1741 | 1744 |
1754 * | 1757 * |
1755 * conf->client_large_buffers.num = 0; | 1758 * conf->client_large_buffers.num = 0; |
1756 */ | 1759 */ |
1757 | 1760 |
1758 if (ngx_array_init(&cscf->locations, cf->pool, 4, sizeof(void *)) | 1761 if (ngx_array_init(&cscf->locations, cf->pool, 4, sizeof(void *)) |
1759 == NGX_ERROR) | 1762 == NGX_ERROR) |
1760 { | 1763 { |
1761 return NGX_CONF_ERROR; | 1764 return NGX_CONF_ERROR; |
1762 } | 1765 } |
1763 | 1766 |
1764 if (ngx_array_init(&cscf->listen, cf->pool, 4, sizeof(ngx_http_listen_t)) | 1767 if (ngx_array_init(&cscf->listen, cf->pool, 4, sizeof(ngx_http_listen_t)) |
1765 == NGX_ERROR) | 1768 == NGX_ERROR) |
1766 { | 1769 { |
1767 return NGX_CONF_ERROR; | 1770 return NGX_CONF_ERROR; |
1768 } | 1771 } |
1769 | 1772 |
1770 if (ngx_array_init(&cscf->server_names, cf->pool, 4, | 1773 if (ngx_array_init(&cscf->server_names, cf->pool, 4, |
1771 sizeof(ngx_http_server_name_t)) == NGX_ERROR) | 1774 sizeof(ngx_http_server_name_t)) |
1775 == NGX_ERROR) | |
1772 { | 1776 { |
1773 return NGX_CONF_ERROR; | 1777 return NGX_CONF_ERROR; |
1774 } | 1778 } |
1775 | 1779 |
1776 cscf->connection_pool_size = NGX_CONF_UNSET_SIZE; | 1780 cscf->connection_pool_size = NGX_CONF_UNSET_SIZE; |
1788 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) | 1792 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) |
1789 { | 1793 { |
1790 ngx_http_core_srv_conf_t *prev = parent; | 1794 ngx_http_core_srv_conf_t *prev = parent; |
1791 ngx_http_core_srv_conf_t *conf = child; | 1795 ngx_http_core_srv_conf_t *conf = child; |
1792 | 1796 |
1793 ngx_http_listen_t *ls; | 1797 ngx_http_listen_t *ls; |
1794 ngx_http_server_name_t *sn; | 1798 ngx_http_server_name_t *sn; |
1795 ngx_http_core_main_conf_t *cmcf; | |
1796 | 1799 |
1797 /* TODO: it does not merge, it inits only */ | 1800 /* TODO: it does not merge, it inits only */ |
1798 | 1801 |
1799 if (conf->listen.nelts == 0) { | 1802 if (conf->listen.nelts == 0) { |
1800 ls = ngx_array_push(&conf->listen); | 1803 ls = ngx_array_push(&conf->listen); |
1835 return NGX_CONF_ERROR; | 1838 return NGX_CONF_ERROR; |
1836 } | 1839 } |
1837 | 1840 |
1838 sn->name.len = ngx_strlen(sn->name.data); | 1841 sn->name.len = ngx_strlen(sn->name.data); |
1839 sn->core_srv_conf = conf; | 1842 sn->core_srv_conf = conf; |
1840 sn->wildcard = 0; | |
1841 | |
1842 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
1843 | |
1844 if (cmcf->max_server_name_len < sn->name.len) { | |
1845 cmcf->max_server_name_len = sn->name.len; | |
1846 } | |
1847 } | 1843 } |
1848 | 1844 |
1849 ngx_conf_merge_size_value(conf->connection_pool_size, | 1845 ngx_conf_merge_size_value(conf->connection_pool_size, |
1850 prev->connection_pool_size, 256); | 1846 prev->connection_pool_size, 256); |
1851 ngx_conf_merge_size_value(conf->request_pool_size, | 1847 ngx_conf_merge_size_value(conf->request_pool_size, |
2277 | 2273 |
2278 | 2274 |
2279 static char * | 2275 static char * |
2280 ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 2276 ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
2281 { | 2277 { |
2282 ngx_http_core_srv_conf_t *scf = conf; | 2278 ngx_http_core_srv_conf_t *cscf = conf; |
2283 | 2279 |
2284 ngx_uint_t i; | 2280 u_char ch; |
2285 ngx_str_t *value; | 2281 ngx_str_t *value, name; |
2286 ngx_http_server_name_t *sn; | 2282 ngx_uint_t i; |
2287 ngx_http_core_main_conf_t *cmcf; | 2283 ngx_http_server_name_t *sn; |
2288 | |
2289 /* TODO: warn about duplicate 'server_name' directives */ | |
2290 | |
2291 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
2292 | 2284 |
2293 value = cf->args->elts; | 2285 value = cf->args->elts; |
2294 | 2286 |
2287 ch = value[1].data[0]; | |
2288 | |
2289 if (cscf->server_name.data == NULL && value[1].len) { | |
2290 if (ch == '*') { | |
2291 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2292 "first server name \"%V\" must not be wildcard", | |
2293 &value[1]); | |
2294 return NGX_CONF_ERROR; | |
2295 } | |
2296 | |
2297 name = value[1]; | |
2298 | |
2299 if (ch == '.') { | |
2300 name.len--; | |
2301 name.data++; | |
2302 } | |
2303 | |
2304 cscf->server_name.len = name.len; | |
2305 cscf->server_name.data = ngx_pstrdup(cf->pool, &name); | |
2306 if (cscf->server_name.data == NULL) { | |
2307 return NGX_CONF_ERROR; | |
2308 } | |
2309 } | |
2310 | |
2295 for (i = 1; i < cf->args->nelts; i++) { | 2311 for (i = 1; i < cf->args->nelts; i++) { |
2296 if (value[i].len == 0) { | 2312 |
2313 ch = value[i].data[0]; | |
2314 | |
2315 if (value[i].len == 0 | |
2316 || (ch == '*' && (value[i].len < 3 || value[i].data[1] != '.')) | |
2317 || (ch == '.' && value[i].len < 2)) | |
2318 { | |
2297 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 2319 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2298 "server name \"%V\" is invalid " | 2320 "server name \"%V\" is invalid", &value[i]); |
2299 "in \"%V\" directive", | |
2300 &value[i], &cmd->name); | |
2301 return NGX_CONF_ERROR; | 2321 return NGX_CONF_ERROR; |
2302 } | 2322 } |
2303 | 2323 |
2304 sn = ngx_array_push(&scf->server_names); | 2324 sn = ngx_array_push(&cscf->server_names); |
2305 if (sn == NULL) { | 2325 if (sn == NULL) { |
2306 return NGX_CONF_ERROR; | 2326 return NGX_CONF_ERROR; |
2307 } | 2327 } |
2308 | 2328 |
2309 sn->name.len = value[i].len; | 2329 sn->name.len = value[i].len; |
2310 sn->name.data = value[i].data; | 2330 sn->name.data = value[i].data; |
2311 sn->core_srv_conf = scf; | 2331 sn->core_srv_conf = cscf; |
2312 | |
2313 if (sn->name.data[0] == '*') { | |
2314 sn->name.len--; | |
2315 sn->name.data++; | |
2316 sn->wildcard = 1; | |
2317 | |
2318 } else { | |
2319 sn->wildcard = 0; | |
2320 } | |
2321 | |
2322 if (cmcf->max_server_name_len < sn->name.len) { | |
2323 cmcf->max_server_name_len = sn->name.len; | |
2324 } | |
2325 } | 2332 } |
2326 | 2333 |
2327 return NGX_CONF_OK; | 2334 return NGX_CONF_OK; |
2328 } | 2335 } |
2329 | 2336 |