30 static char *ngx_http_merge_servers(
ngx_conf_t *cf,
33 static char *ngx_http_merge_locations(
ngx_conf_t *cf,
44 static void ngx_http_create_locations_list(
ngx_queue_t *locations,
54 static ngx_int_t ngx_http_cmp_conf_addrs(
const void *one,
const void *two);
55 static int ngx_libc_cdecl ngx_http_cmp_dns_wildcards(
const void *one,
104 &ngx_http_module_ctx,
270 rv = ngx_http_merge_servers(cf, cmcf, module, mi);
283 if (ngx_http_init_locations(cf, cscfp[s], clcf) !=
NGX_OK) {
287 if (ngx_http_init_static_location_trees(cf, clcf) !=
NGX_OK) {
293 if (ngx_http_init_phases(cf, cmcf) !=
NGX_OK) {
297 if (ngx_http_init_headers_in_hash(cf, cmcf) !=
NGX_OK) {
328 if (ngx_http_init_phase_handlers(cf, cmcf) !=
NGX_OK) {
335 if (ngx_http_optimize_servers(cf, cmcf, cmcf->
ports) !=
NGX_OK) {
434 hash.
name =
"headers_in_hash";
451 ngx_uint_t find_config_index, use_rewrite, use_access;
458 find_config_index = 0;
462 n = use_rewrite + use_access + cmcf->
try_files + 1 ;
491 find_config_index = n;
510 ph->
next = find_config_index;
607 rv = ngx_http_merge_locations(cf, clcf->
locations,
634 if (locations == NULL) {
685 if (locations == NULL) {
706 if (ngx_http_init_locations(cf, NULL, clcf) !=
NGX_OK) {
758 *(clcfp++) = lq->
exact;
776 pclcf->regex_locations = clcfp;
784 *(clcfp++) = lq->
exact;
799 ngx_http_init_static_location_trees(
ngx_conf_t *cf,
808 if (locations == NULL) {
824 if (ngx_http_init_static_location_trees(cf, clcf) !=
NGX_OK) {
829 if (ngx_http_join_exact_locations(cf, locations) !=
NGX_OK) {
833 ngx_http_create_locations_list(locations,
ngx_queue_head(locations));
850 if (*locations == NULL) {
853 if (*locations == NULL) {
935 if (first->regex && !second->regex) {
940 if (!first->regex && second->regex) {
945 if (first->regex || second->regex) {
982 "duplicate location \"%V\" in %s:%ui",
1040 ngx_http_create_locations_list(locations, x);
1057 ngx_http_create_locations_list(locations, x);
1095 node->
len = (u_char) len;
1108 node->
left = ngx_http_create_locations_tree(cf, locations, prefix);
1109 if (node->
left == NULL) {
1119 node->
right = ngx_http_create_locations_tree(cf, &tail, prefix);
1120 if (node->
right == NULL) {
1130 node->
tree = ngx_http_create_locations_tree(cf, &lq->
list, prefix + len);
1131 if (node->
tree == NULL) {
1145 struct sockaddr *sa;
1146 struct sockaddr_in *sin;
1149 #if (NGX_HAVE_INET6)
1150 struct sockaddr_in6 *sin6;
1155 if (cmcf->
ports == NULL) {
1158 if (cmcf->
ports == NULL) {
1165 switch (sa->sa_family) {
1167 #if (NGX_HAVE_INET6)
1169 sin6 = &lsopt->
u.sockaddr_in6;
1170 p = sin6->sin6_port;
1174 #if (NGX_HAVE_UNIX_DOMAIN)
1189 if (p != port[i].port || sa->sa_family != port[i].
family) {
1195 return ngx_http_add_addresses(cf, cscf, &port[i], lsopt);
1205 port->
family = sa->sa_family;
1209 return ngx_http_add_address(cf, cscf, port, lsopt);
1220 struct sockaddr *sa;
1222 #if (NGX_HAVE_UNIX_DOMAIN)
1223 struct sockaddr_un *saun;
1239 switch (sa->sa_family) {
1241 #if (NGX_HAVE_INET6)
1243 off = offsetof(
struct sockaddr_in6, sin6_addr);
1248 #if (NGX_HAVE_UNIX_DOMAIN)
1250 off = offsetof(
struct sockaddr_un, sun_path);
1251 len =
sizeof(saun->sun_path);
1256 off = offsetof(
struct sockaddr_in, sin_addr);
1267 if (
ngx_memcmp(p, addr[i].opt.u.sockaddr_data + off, len) != 0) {
1273 if (ngx_http_add_server(cf, cscf, &addr[i]) !=
NGX_OK) {
1281 ssl = lsopt->ssl || addr[
i].
opt.ssl;
1284 spdy = lsopt->spdy || addr[
i].
opt.spdy;
1289 if (addr[i].opt.set) {
1291 "duplicate listen options for %s", addr[i].opt.addr);
1295 addr[
i].
opt = *lsopt;
1302 if (default_server) {
1304 "a duplicate default server for %s", addr[i].opt.addr);
1314 addr[
i].
opt.ssl = ssl;
1317 addr[
i].
opt.spdy = spdy;
1325 return ngx_http_add_address(cf, cscf, port, lsopt);
1349 #if (NGX_HTTP_SPDY && NGX_HTTP_SSL && !defined TLSEXT_TYPE_next_proto_neg)
1350 if (lsopt->spdy && lsopt->ssl) {
1352 "nginx was built without OpenSSL NPN support, "
1353 "SPDY is not enabled for %s", lsopt->
addr);
1374 return ngx_http_add_server(cf, cscf, addr);
1398 if (server[i] == cscf) {
1400 "a duplicate listen %s", addr->
opt.
addr);
1407 if (server == NULL) {
1425 if (ports == NULL) {
1430 for (p = 0; p < ports->
nelts; p++) {
1443 if (addr[a].servers.nelts > 1
1445 || addr[a].default_server->captures
1449 if (ngx_http_server_names(cf, cmcf, &addr[a]) !=
NGX_OK) {
1455 if (ngx_http_init_listening(cf, &port[p]) !=
NGX_OK) {
1502 if (name[n].regex) {
1517 "invalid server name or wildcard \"%V\" on %s",
1524 "conflicting server name \"%V\" on %s, ignored",
1533 hash.
name =
"server_names_hash";
1589 addr->nregex = regex;
1591 if (addr->regex == NULL) {
1602 if (name[n].regex) {
1603 addr->regex[i++] = name[n];
1621 ngx_http_cmp_conf_addrs(
const void *one,
const void *two)
1655 ngx_http_cmp_dns_wildcards(
const void *one,
const void *two)
1684 if (addr[last - 1].opt.wildcard) {
1696 if (bind_wildcard && !addr[i].opt.bind) {
1701 ls = ngx_http_add_listening(cf, &addr[i]);
1707 if (hport == NULL) {
1713 if (i == last - 1) {
1723 #if (NGX_HAVE_INET6)
1725 if (ngx_http_add_addrs6(cf, hport, addr) !=
NGX_OK) {
1731 if (ngx_http_add_addrs(cf, hport, addr) !=
NGX_OK) {
1773 ngx_iocp_conf_t *iocpcf = NULL;
1778 if (iocpcf && iocpcf->acceptex_read) {
1789 #if (NGX_HAVE_KEEPALIVE_TUNABLE)
1790 ls->keepidle = addr->
opt.tcp_keepidle;
1791 ls->keepintvl = addr->
opt.tcp_keepintvl;
1792 ls->keepcnt = addr->
opt.tcp_keepcnt;
1795 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
1796 ls->accept_filter = addr->
opt.accept_filter;
1799 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
1800 ls->deferred_accept = addr->
opt.deferred_accept;
1803 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
1804 ls->ipv6only = addr->
opt.ipv6only;
1807 #if (NGX_HAVE_SETFIB)
1808 ls->setfib = addr->
opt.setfib;
1821 struct sockaddr_in *sin;
1826 if (hport->
addrs == NULL) {
1830 addrs = hport->
addrs;
1832 for (i = 0; i < hport->
naddrs; i++) {
1835 addrs[
i].
addr = sin->sin_addr.s_addr;
1844 if (addr[i].hash.buckets == NULL
1850 && addr[i].nregex == 0
1869 vn->
regex = addr[
i].regex;
1877 #if (NGX_HAVE_INET6)
1884 ngx_http_in6_addr_t *addrs6;
1885 struct sockaddr_in6 *sin6;
1889 hport->
naddrs *
sizeof(ngx_http_in6_addr_t));
1890 if (hport->
addrs == NULL) {
1894 addrs6 = hport->
addrs;
1896 for (i = 0; i < hport->
naddrs; i++) {
1898 sin6 = &addr[
i].
opt.
u.sockaddr_in6;
1899 addrs6[
i].addr6 = sin6->sin6_addr;
1902 addrs6[
i].conf.ssl = addr[
i].
opt.ssl;
1905 addrs6[
i].conf.spdy = addr[
i].
opt.spdy;
1908 if (addr[i].hash.buckets == NULL
1914 && addr[i].nregex == 0
1926 addrs6[
i].conf.virtual_names = vn;
1933 vn->
regex = addr[
i].regex;
1955 if (*types == (
void *) -1) {
1959 default_type = cmd->
post;
1961 if (*types == NULL) {
1963 if (*types == NULL) {
1973 type->
key = *default_type;
1976 type->
value = (
void *) 4;
1984 if (value[i].len == 1 && value[i].data[0] ==
'*') {
1985 *types = (
void *) -1;
1992 type = (*types)->elts;
1993 for (n = 0; n < (*types)->nelts; n++) {
1995 if (
ngx_strcmp(value[i].data, type[n].key.data) == 0) {
1997 "duplicate MIME type \"%V\"", &value[i]);
2007 type->
key = value[
i];
2009 type->
value = (
void *) 4;
2025 if (*keys == (
void *) -1) {
2029 hash.
hash = types_hash;
2033 hash.
name =
"test_types_hash";
2044 if (prev_types_hash->
buckets == NULL) {
2046 if (*prev_keys == NULL) {
2054 }
else if (*prev_keys == (
void *) -1) {
2059 hash.
hash = prev_types_hash;
2063 hash.
name =
"test_types_hash";
2067 if (
ngx_hash_init(&hash, (*prev_keys)->elts, (*prev_keys)->nelts)
2074 *types_hash = *prev_types_hash;
2088 if (*types == NULL) {
2092 while (default_type->
len) {
2099 type->
key = *default_type;
2102 type->
value = (
void *) 4;