이 문서는 nginx 1.8.1 소스코드 컴파일을 한다는 중심으로 서술합니다.
nginx-1.8.1/src/http/ngx_http_header_filter_module.c
약 48행쯤
static char ngx_http_server_string[] = "Server: nginx" CRLF;
static char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF;
주석처리
약 281행쯤 "if (r->headers_out.server == NULL) {" 부분 주석처리
/* if (r->headers_out.server == NULL) { len += clcf->server_tokens ? sizeof(ngx_http_server_full_string) - 1: sizeof(ngx_http_server_string) - 1; } */
458행쯤 " if (r->headers_out.server == NULL) {" 부분 주석처리
/* if (r->headers_out.server == NULL) { if (clcf->server_tokens) { p = (u_char *) ngx_http_server_full_string; len = sizeof(ngx_http_server_full_string) - 1; } else { p = (u_char *) ngx_http_server_string; len = sizeof(ngx_http_server_string) - 1; } b->last = ngx_cpymem(b->last, p, len); } */
결과
$ curl -I localhost:8081
HTTP/1.1 200 OK
Date: Tue, 27 Sep 2016 15:08:52 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 27 Sep 2016 15:06:39 GMT
Connection: keep-alive
ETag: "57ea8aff-264"
Accept-Ranges: bytes
만약 웹서버 fingerprinting을 완벽히 막고싶다면 기본 에러페이지(300-500대 에러)를 모조리 수정 할 것을 권장합니다.
server_tokens off; 설정으로 버전만 숨겨도 충분하다고 생각합니다.
어차피 전세계 웹서버 시장을 아파치, nginx, IIS가 사이좋게 나눠먹고 있는데 셋 중 어느 것인지 숨긴다고 보안상 도움이 될 것 같지는 않거든요. 아무리 숨겨도 Metasploit처럼 자동화된 해킹툴을 잠깐만 돌려 보면 어느 서버의 대략 어느 버전인지 알 수 있어요. 게다가 소스 컴파일로 잃는 것이 얻는 것보다 더 많을지도... (소스 컴파일로 설치하시는 분들 중 중요한 보안패치가 나왔을 때 apt나 yum보다 빨리 업데이트하시는 분은 본 적이 없습니다.)