Mercurial > hg > nginx
comparison src/http/ngx_http_core_module.c @ 6432:cf3e75cfa951
Added variables support to server_tokens.
It can now be set to "off" conditionally, e.g. using the map
directive.
An empty value will disable the emission of the Server: header
and the signature in error messages generated by nginx.
Any other value is treated as "on", meaning that full nginx
version is emitted in the Server: header and error messages
generated by nginx.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Tue, 15 Mar 2016 13:36:19 +0300 |
parents | cf5e822cf470 |
children | fc72784b1f52 |
comparison
equal
deleted
inserted
replaced
6431:3b9c6b91d988 | 6432:cf3e75cfa951 |
---|---|
56 static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, | 56 static char *ngx_http_core_limit_except(ngx_conf_t *cf, ngx_command_t *cmd, |
57 void *conf); | 57 void *conf); |
58 static char *ngx_http_core_set_aio(ngx_conf_t *cf, ngx_command_t *cmd, | 58 static char *ngx_http_core_set_aio(ngx_conf_t *cf, ngx_command_t *cmd, |
59 void *conf); | 59 void *conf); |
60 static char *ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd, | 60 static char *ngx_http_core_directio(ngx_conf_t *cf, ngx_command_t *cmd, |
61 void *conf); | |
62 static char *ngx_http_core_server_tokens(ngx_conf_t *cf, ngx_command_t *cmd, | |
61 void *conf); | 63 void *conf); |
62 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, | 64 static char *ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, |
63 void *conf); | 65 void *conf); |
64 static char *ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd, | 66 static char *ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd, |
65 void *conf); | 67 void *conf); |
583 NGX_HTTP_LOC_CONF_OFFSET, | 585 NGX_HTTP_LOC_CONF_OFFSET, |
584 offsetof(ngx_http_core_loc_conf_t, recursive_error_pages), | 586 offsetof(ngx_http_core_loc_conf_t, recursive_error_pages), |
585 NULL }, | 587 NULL }, |
586 | 588 |
587 { ngx_string("server_tokens"), | 589 { ngx_string("server_tokens"), |
588 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | 590 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
589 ngx_conf_set_flag_slot, | 591 ngx_http_core_server_tokens, |
590 NGX_HTTP_LOC_CONF_OFFSET, | 592 NGX_HTTP_LOC_CONF_OFFSET, |
591 offsetof(ngx_http_core_loc_conf_t, server_tokens), | 593 0, |
592 NULL }, | 594 NULL }, |
593 | 595 |
594 { ngx_string("if_modified_since"), | 596 { ngx_string("if_modified_since"), |
595 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | 597 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
596 ngx_conf_set_enum_slot, | 598 ngx_conf_set_enum_slot, |
3633 clcf->msie_padding = NGX_CONF_UNSET; | 3635 clcf->msie_padding = NGX_CONF_UNSET; |
3634 clcf->msie_refresh = NGX_CONF_UNSET; | 3636 clcf->msie_refresh = NGX_CONF_UNSET; |
3635 clcf->log_not_found = NGX_CONF_UNSET; | 3637 clcf->log_not_found = NGX_CONF_UNSET; |
3636 clcf->log_subrequest = NGX_CONF_UNSET; | 3638 clcf->log_subrequest = NGX_CONF_UNSET; |
3637 clcf->recursive_error_pages = NGX_CONF_UNSET; | 3639 clcf->recursive_error_pages = NGX_CONF_UNSET; |
3638 clcf->server_tokens = NGX_CONF_UNSET; | |
3639 clcf->chunked_transfer_encoding = NGX_CONF_UNSET; | 3640 clcf->chunked_transfer_encoding = NGX_CONF_UNSET; |
3640 clcf->etag = NGX_CONF_UNSET; | 3641 clcf->etag = NGX_CONF_UNSET; |
3642 clcf->server_tokens = NGX_CONF_UNSET_UINT; | |
3641 clcf->types_hash_max_size = NGX_CONF_UNSET_UINT; | 3643 clcf->types_hash_max_size = NGX_CONF_UNSET_UINT; |
3642 clcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT; | 3644 clcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT; |
3643 | 3645 |
3644 clcf->open_file_cache = NGX_CONF_UNSET_PTR; | 3646 clcf->open_file_cache = NGX_CONF_UNSET_PTR; |
3645 clcf->open_file_cache_valid = NGX_CONF_UNSET; | 3647 clcf->open_file_cache_valid = NGX_CONF_UNSET; |
3898 ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0); | 3900 ngx_conf_merge_value(conf->msie_refresh, prev->msie_refresh, 0); |
3899 ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1); | 3901 ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1); |
3900 ngx_conf_merge_value(conf->log_subrequest, prev->log_subrequest, 0); | 3902 ngx_conf_merge_value(conf->log_subrequest, prev->log_subrequest, 0); |
3901 ngx_conf_merge_value(conf->recursive_error_pages, | 3903 ngx_conf_merge_value(conf->recursive_error_pages, |
3902 prev->recursive_error_pages, 0); | 3904 prev->recursive_error_pages, 0); |
3903 ngx_conf_merge_value(conf->server_tokens, prev->server_tokens, 1); | |
3904 ngx_conf_merge_value(conf->chunked_transfer_encoding, | 3905 ngx_conf_merge_value(conf->chunked_transfer_encoding, |
3905 prev->chunked_transfer_encoding, 1); | 3906 prev->chunked_transfer_encoding, 1); |
3906 ngx_conf_merge_value(conf->etag, prev->etag, 1); | 3907 ngx_conf_merge_value(conf->etag, prev->etag, 1); |
3908 | |
3909 if (conf->server_tokens == NGX_CONF_UNSET_UINT) { | |
3910 ngx_conf_merge_uint_value(conf->server_tokens, prev->server_tokens, 1); | |
3911 conf->server_tokens_value = prev->server_tokens_value; | |
3912 } | |
3907 | 3913 |
3908 ngx_conf_merge_ptr_value(conf->open_file_cache, | 3914 ngx_conf_merge_ptr_value(conf->open_file_cache, |
3909 prev->open_file_cache, NULL); | 3915 prev->open_file_cache, NULL); |
3910 | 3916 |
3911 ngx_conf_merge_sec_value(conf->open_file_cache_valid, | 3917 ngx_conf_merge_sec_value(conf->open_file_cache_valid, |
4785 return NGX_CONF_OK; | 4791 return NGX_CONF_OK; |
4786 } | 4792 } |
4787 | 4793 |
4788 | 4794 |
4789 static char * | 4795 static char * |
4796 ngx_http_core_server_tokens(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
4797 { | |
4798 ngx_http_core_loc_conf_t *clcf = conf; | |
4799 | |
4800 ngx_str_t *value; | |
4801 ngx_http_compile_complex_value_t ccv; | |
4802 | |
4803 if (clcf->server_tokens != NGX_CONF_UNSET_UINT) { | |
4804 return "is duplicate"; | |
4805 } | |
4806 | |
4807 value = cf->args->elts; | |
4808 | |
4809 if (ngx_strcmp(value[1].data, "on") == 0) { | |
4810 clcf->server_tokens = 1; | |
4811 return NGX_CONF_OK; | |
4812 } | |
4813 | |
4814 if (ngx_strcmp(value[1].data, "off") == 0) { | |
4815 clcf->server_tokens = 0; | |
4816 return NGX_CONF_OK; | |
4817 } | |
4818 | |
4819 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); | |
4820 | |
4821 ccv.cf = cf; | |
4822 ccv.value = &value[1]; | |
4823 ccv.complex_value = &clcf->server_tokens_value; | |
4824 | |
4825 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { | |
4826 return NGX_CONF_ERROR; | |
4827 } | |
4828 | |
4829 clcf->server_tokens = 2; | |
4830 | |
4831 return NGX_CONF_OK; | |
4832 } | |
4833 | |
4834 | |
4835 static char * | |
4790 ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 4836 ngx_http_core_error_page(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
4791 { | 4837 { |
4792 ngx_http_core_loc_conf_t *clcf = conf; | 4838 ngx_http_core_loc_conf_t *clcf = conf; |
4793 | 4839 |
4794 u_char *p; | 4840 u_char *p; |