Mercurial > hg > nginx
comparison src/http/ngx_http_core_module.c @ 3775:2902fc8487ae
add default listen port at the end of server block parsing instead of
merge phase: otherwise the first server without an listen directive
did not become the default server if there was no explicit default server;
the bug has been introduced in r3218
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 11 Oct 2010 18:48:18 +0000 |
parents | 5ceb0f624233 |
children | 173a45374a97 |
comparison
equal
deleted
inserted
replaced
3774:5ceb0f624233 | 3775:2902fc8487ae |
---|---|
2425 char *rv; | 2425 char *rv; |
2426 void *mconf; | 2426 void *mconf; |
2427 ngx_uint_t i; | 2427 ngx_uint_t i; |
2428 ngx_conf_t pcf; | 2428 ngx_conf_t pcf; |
2429 ngx_http_module_t *module; | 2429 ngx_http_module_t *module; |
2430 struct sockaddr_in *sin; | |
2430 ngx_http_conf_ctx_t *ctx, *http_ctx; | 2431 ngx_http_conf_ctx_t *ctx, *http_ctx; |
2432 ngx_http_listen_opt_t lsopt; | |
2431 ngx_http_core_srv_conf_t *cscf, **cscfp; | 2433 ngx_http_core_srv_conf_t *cscf, **cscfp; |
2432 ngx_http_core_main_conf_t *cmcf; | 2434 ngx_http_core_main_conf_t *cmcf; |
2433 | 2435 |
2434 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); | 2436 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); |
2435 if (ctx == NULL) { | 2437 if (ctx == NULL) { |
2503 cf->cmd_type = NGX_HTTP_SRV_CONF; | 2505 cf->cmd_type = NGX_HTTP_SRV_CONF; |
2504 | 2506 |
2505 rv = ngx_conf_parse(cf, NULL); | 2507 rv = ngx_conf_parse(cf, NULL); |
2506 | 2508 |
2507 *cf = pcf; | 2509 *cf = pcf; |
2510 | |
2511 if (rv == NGX_CONF_OK && !cscf->listen) { | |
2512 ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t)); | |
2513 | |
2514 sin = &lsopt.u.sockaddr_in; | |
2515 | |
2516 sin->sin_family = AF_INET; | |
2517 #if (NGX_WIN32) | |
2518 sin->sin_port = htons(80); | |
2519 #else | |
2520 sin->sin_port = htons((getuid() == 0) ? 80 : 8000); | |
2521 #endif | |
2522 sin->sin_addr.s_addr = INADDR_ANY; | |
2523 | |
2524 lsopt.socklen = sizeof(struct sockaddr_in); | |
2525 | |
2526 lsopt.backlog = NGX_LISTEN_BACKLOG; | |
2527 lsopt.rcvbuf = -1; | |
2528 lsopt.sndbuf = -1; | |
2529 #if (NGX_HAVE_SETFIB) | |
2530 lsopt.setfib = -1; | |
2531 #endif | |
2532 lsopt.wildcard = 1; | |
2533 | |
2534 (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr, | |
2535 NGX_SOCKADDR_STRLEN, 1); | |
2536 | |
2537 if (ngx_http_add_listen(cf, cscf, &lsopt) != NGX_OK) { | |
2538 return NGX_CONF_ERROR; | |
2539 } | |
2540 } | |
2508 | 2541 |
2509 return rv; | 2542 return rv; |
2510 } | 2543 } |
2511 | 2544 |
2512 | 2545 |
2944 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) | 2977 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) |
2945 { | 2978 { |
2946 ngx_http_core_srv_conf_t *prev = parent; | 2979 ngx_http_core_srv_conf_t *prev = parent; |
2947 ngx_http_core_srv_conf_t *conf = child; | 2980 ngx_http_core_srv_conf_t *conf = child; |
2948 | 2981 |
2949 struct sockaddr_in *sin; | |
2950 ngx_http_listen_opt_t lsopt; | |
2951 ngx_http_server_name_t *sn; | 2982 ngx_http_server_name_t *sn; |
2952 | 2983 |
2953 /* TODO: it does not merge, it inits only */ | 2984 /* TODO: it does not merge, it inits only */ |
2954 | 2985 |
2955 ngx_conf_merge_size_value(conf->connection_pool_size, | 2986 ngx_conf_merge_size_value(conf->connection_pool_size, |
2976 | 3007 |
2977 ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1); | 3008 ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1); |
2978 | 3009 |
2979 ngx_conf_merge_value(conf->underscores_in_headers, | 3010 ngx_conf_merge_value(conf->underscores_in_headers, |
2980 prev->underscores_in_headers, 0); | 3011 prev->underscores_in_headers, 0); |
2981 | |
2982 if (!conf->listen) { | |
2983 ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t)); | |
2984 | |
2985 sin = &lsopt.u.sockaddr_in; | |
2986 | |
2987 sin->sin_family = AF_INET; | |
2988 #if (NGX_WIN32) | |
2989 sin->sin_port = htons(80); | |
2990 #else | |
2991 sin->sin_port = htons((getuid() == 0) ? 80 : 8000); | |
2992 #endif | |
2993 sin->sin_addr.s_addr = INADDR_ANY; | |
2994 | |
2995 lsopt.socklen = sizeof(struct sockaddr_in); | |
2996 | |
2997 lsopt.backlog = NGX_LISTEN_BACKLOG; | |
2998 lsopt.rcvbuf = -1; | |
2999 lsopt.sndbuf = -1; | |
3000 #if (NGX_HAVE_SETFIB) | |
3001 lsopt.setfib = -1; | |
3002 #endif | |
3003 lsopt.wildcard = 1; | |
3004 | |
3005 (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr, | |
3006 NGX_SOCKADDR_STRLEN, 1); | |
3007 | |
3008 if (ngx_http_add_listen(cf, conf, &lsopt) != NGX_OK) { | |
3009 return NGX_CONF_ERROR; | |
3010 } | |
3011 } | |
3012 | 3012 |
3013 if (conf->server_name.data == NULL) { | 3013 if (conf->server_name.data == NULL) { |
3014 ngx_str_set(&conf->server_name, ""); | 3014 ngx_str_set(&conf->server_name, ""); |
3015 | 3015 |
3016 sn = ngx_array_push(&conf->server_names); | 3016 sn = ngx_array_push(&conf->server_names); |