mirror of
https://github.com/nginx/nginx.git
synced 2025-06-22 05:40:48 +08:00
server_tokens
This commit is contained in:
parent
9e039cfc9e
commit
070cf22ab4
@ -434,6 +434,13 @@ static ngx_command_t ngx_http_core_commands[] = {
|
|||||||
offsetof(ngx_http_core_loc_conf_t, recursive_error_pages),
|
offsetof(ngx_http_core_loc_conf_t, recursive_error_pages),
|
||||||
NULL },
|
NULL },
|
||||||
|
|
||||||
|
{ ngx_string("server_tokens"),
|
||||||
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
||||||
|
ngx_conf_set_flag_slot,
|
||||||
|
NGX_HTTP_LOC_CONF_OFFSET,
|
||||||
|
offsetof(ngx_http_core_loc_conf_t, server_tokens),
|
||||||
|
NULL },
|
||||||
|
|
||||||
{ ngx_string("error_page"),
|
{ ngx_string("error_page"),
|
||||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|
||||||
|NGX_CONF_2MORE,
|
|NGX_CONF_2MORE,
|
||||||
@ -2390,6 +2397,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
|
|||||||
lcf->msie_refresh = NGX_CONF_UNSET;
|
lcf->msie_refresh = NGX_CONF_UNSET;
|
||||||
lcf->log_not_found = NGX_CONF_UNSET;
|
lcf->log_not_found = NGX_CONF_UNSET;
|
||||||
lcf->recursive_error_pages = NGX_CONF_UNSET;
|
lcf->recursive_error_pages = NGX_CONF_UNSET;
|
||||||
|
lcf->server_tokens = NGX_CONF_UNSET;
|
||||||
lcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
|
lcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
|
||||||
lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
||||||
lcf->open_file_cache = NGX_CONF_UNSET_PTR;
|
lcf->open_file_cache = NGX_CONF_UNSET_PTR;
|
||||||
@ -2578,6 +2586,7 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||||||
ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1);
|
ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1);
|
||||||
ngx_conf_merge_value(conf->recursive_error_pages,
|
ngx_conf_merge_value(conf->recursive_error_pages,
|
||||||
prev->recursive_error_pages, 0);
|
prev->recursive_error_pages, 0);
|
||||||
|
ngx_conf_merge_value(conf->server_tokens, prev->server_tokens, 1);
|
||||||
|
|
||||||
ngx_conf_merge_ptr_value(conf->open_file_cache,
|
ngx_conf_merge_ptr_value(conf->open_file_cache,
|
||||||
prev->open_file_cache, NULL);
|
prev->open_file_cache, NULL);
|
||||||
|
@ -285,6 +285,7 @@ struct ngx_http_core_loc_conf_s {
|
|||||||
ngx_flag_t msie_refresh; /* msie_refresh */
|
ngx_flag_t msie_refresh; /* msie_refresh */
|
||||||
ngx_flag_t log_not_found; /* log_not_found */
|
ngx_flag_t log_not_found; /* log_not_found */
|
||||||
ngx_flag_t recursive_error_pages; /* recursive_error_pages */
|
ngx_flag_t recursive_error_pages; /* recursive_error_pages */
|
||||||
|
ngx_flag_t server_tokens; /* server_tokens */
|
||||||
|
|
||||||
ngx_array_t *error_pages; /* error_page */
|
ngx_array_t *error_pages; /* error_page */
|
||||||
|
|
||||||
|
@ -45,7 +45,8 @@ ngx_module_t ngx_http_header_filter_module = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static char ngx_http_server_string[] = "Server: " NGINX_VER CRLF;
|
static char ngx_http_server_string[] = "Server: nginx" CRLF;
|
||||||
|
static char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF;
|
||||||
|
|
||||||
|
|
||||||
static ngx_str_t ngx_http_status_lines[] = {
|
static ngx_str_t ngx_http_status_lines[] = {
|
||||||
@ -237,8 +238,11 @@ ngx_http_header_filter(ngx_http_request_t *r)
|
|||||||
len += ngx_http_status_lines[status].len;
|
len += ngx_http_status_lines[status].len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
||||||
|
|
||||||
if (r->headers_out.server == NULL) {
|
if (r->headers_out.server == NULL) {
|
||||||
len += sizeof(ngx_http_server_string) - 1;
|
len += clcf->server_tokens ? sizeof(ngx_http_server_full_string) - 1:
|
||||||
|
sizeof(ngx_http_server_string) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r->headers_out.date == NULL) {
|
if (r->headers_out.date == NULL) {
|
||||||
@ -268,8 +272,6 @@ ngx_http_header_filter(ngx_http_request_t *r)
|
|||||||
len += sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1;
|
len += sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
||||||
|
|
||||||
if (r->headers_out.location
|
if (r->headers_out.location
|
||||||
&& r->headers_out.location->value.len
|
&& r->headers_out.location->value.len
|
||||||
&& r->headers_out.location->value.data[0] == '/')
|
&& r->headers_out.location->value.data[0] == '/')
|
||||||
@ -365,8 +367,16 @@ ngx_http_header_filter(ngx_http_request_t *r)
|
|||||||
*b->last++ = CR; *b->last++ = LF;
|
*b->last++ = CR; *b->last++ = LF;
|
||||||
|
|
||||||
if (r->headers_out.server == NULL) {
|
if (r->headers_out.server == NULL) {
|
||||||
b->last = ngx_cpymem(b->last, ngx_http_server_string,
|
if (clcf->server_tokens) {
|
||||||
sizeof(ngx_http_server_string) - 1);
|
p = ngx_http_server_full_string;
|
||||||
|
len = sizeof(ngx_http_server_full_string) - 1;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
p = ngx_http_server_string;
|
||||||
|
len = sizeof(ngx_http_server_string) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
b->last = ngx_cpymem(b->last, p, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r->headers_out.date == NULL) {
|
if (r->headers_out.date == NULL) {
|
||||||
|
@ -10,13 +10,20 @@
|
|||||||
#include <nginx.h>
|
#include <nginx.h>
|
||||||
|
|
||||||
|
|
||||||
static u_char error_tail[] =
|
static u_char error_full_tail[] =
|
||||||
"<hr><center>" NGINX_VER "</center>" CRLF
|
"<hr><center>" NGINX_VER "</center>" CRLF
|
||||||
"</body>" CRLF
|
"</body>" CRLF
|
||||||
"</html>" CRLF
|
"</html>" CRLF
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
static u_char error_tail[] =
|
||||||
|
"<hr><center>nginx</center>" CRLF
|
||||||
|
"</body>" CRLF
|
||||||
|
"</html>" CRLF
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
static u_char ngx_http_msie_stub[] =
|
static u_char ngx_http_msie_stub[] =
|
||||||
"<!-- The padding to disable MSIE's friendly error page -->" CRLF
|
"<!-- The padding to disable MSIE's friendly error page -->" CRLF
|
||||||
"<!-- The padding to disable MSIE's friendly error page -->" CRLF
|
"<!-- The padding to disable MSIE's friendly error page -->" CRLF
|
||||||
@ -471,7 +478,8 @@ ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
|
|||||||
if (!r->zero_body) {
|
if (!r->zero_body) {
|
||||||
if (error_pages[err].len) {
|
if (error_pages[err].len) {
|
||||||
r->headers_out.content_length_n = error_pages[err].len
|
r->headers_out.content_length_n = error_pages[err].len
|
||||||
+ sizeof(error_tail) - 1;
|
+ (clcf->server_tokens ? sizeof(error_full_tail) - 1:
|
||||||
|
sizeof(error_tail) - 1);
|
||||||
|
|
||||||
if (clcf->msie_padding
|
if (clcf->msie_padding
|
||||||
&& r->headers_in.msie
|
&& r->headers_in.msie
|
||||||
@ -568,8 +576,14 @@ ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
b->memory = 1;
|
b->memory = 1;
|
||||||
|
|
||||||
|
if (clcf->server_tokens) {
|
||||||
|
b->pos = error_full_tail;
|
||||||
|
b->last = error_full_tail + sizeof(error_full_tail) - 1;
|
||||||
|
} else {
|
||||||
b->pos = error_tail;
|
b->pos = error_tail;
|
||||||
b->last = error_tail + sizeof(error_tail) - 1;
|
b->last = error_tail + sizeof(error_tail) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
cl->next = ngx_alloc_chain_link(r->pool);
|
cl->next = ngx_alloc_chain_link(r->pool);
|
||||||
if (cl->next == NULL) {
|
if (cl->next == NULL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user