기본적으로 Nginx에서 nginx 버전 정보를 숨기는 것은 간단하게 해결 할수 있다
기본값이 on 상태일때 값을 확인해 보면
|
[root@xinet nginx-1.21.6]# vi /usr/local/nginx/conf/nginx.conf ### version hide server_tokens on; |
이렇게 구성할 경우 버전이 출력된다
|
[root@xinet ~]# curl -IsL https://xinet.kr --insecure HTTP/1.1 200 OK Server: nginx/1.21.7 Date: Fri, 29 Apr 2022 06:58:54 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive Set-Cookie: PHPSESSID=nv5flpefh076b2a92taf95u093; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate Pragma: no-cache Link: <https://xinet.kr/index.php?rest_route=/>; rel="https://api.w.org/" |

버전 정보를 숨기기 위해서는 nginx.conf 환경설정에서 server_tokens 값을 off 로 변경하면 된다
|
[root@xinet nginx-1.21.6]# vi /usr/local/nginx/conf/nginx.conf ### version hide server_tokens off; |
nginx 재시작 후 확인
|
[root@xinet ~]# systemctl restart nginx [root@xinet ~]# curl -IsL https://xinet.kr --insecure HTTP/1.1 200 OK Server: nginx Date: Fri, 29 Apr 2022 07:02:06 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive Set-Cookie: PHPSESSID=1ljq6md9ngrd6q7pm3njstrlst; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate Pragma: no-cache Link: <https://xinet.kr/index.php?rest_route=/>; rel="https://api.w.org/" |
이렇게 하면 버전의 정보를 숨길 수가 있다

웹페이지에서도 확인해보자

그러면 header 값에 server에 nginx 값이 표시가 되는데 이것도 숨길 수가 있다
모듈이 추가해서 이용하면 되는데 사용되믄 모듈은 ngx_security_headers 이용하면 된다
다운로드 후 모듈을 생성 후 추가해주면 된다
|
[root@xinet ~]# cd /usr/local/src/ [root@xinet src]# git clone https://github.com/GetPageSpeed/ngx_security_headers.git |
기본 설치된 버전 없으면 다운로드 있으면 처음 설치 폴더로 가서 모듈 생성 및 복사
|
[root@xinet src]# cd nginx-1.21.6/ [root@xinet nginx-1.21.6]# ./configure --with-compat --add-dynamic-module=/usr/local/src/ngx_security_headers [root@xinet nginx-1.21.6]# make modules [root@xinet nginx-1.21.6]# cp -a objs/ngx_http_security_headers_module.so /usr/local/nginx/modules/ |
모듈이 복사가 되었으면 환경설정 값에 추가
|
[root@xinet nginx-1.21.6]# vi /usr/local/nginx/conf/nginx.conf load_module modules/ngx_http_security_headers_module.so; ### header hide hide_server_tokens on; |
nginx 재시작 및 curl 확인 server 정보가 표시되지 않는다
|
[root@xinet ~]# systemctl restart nginx [root@xinet ~]# curl -IsL https://xinet.kr --insecure HTTP/1.1 200 OK Date: Fri, 29 Apr 2022 06:52:39 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive Set-Cookie: PHPSESSID=ukiujk8i29fo97enqlr4fops2i; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate Pragma: no-cache Link: <https://xinet.kr/index.php?rest_route=/>; rel="https://api.w.org/" |

크롬 웹페이지에서 확인

만약 yum 으로 설치된 환경이라면 해당 설치 후 모듈 추가된거 확인 후 이용하면 된다
|
yum -y install https://extras.getpagespeed.com/release-latest.rpm yum -y install nginx-module-security-headers |
|
load_module modules/ngx_http_headers_more_filter_module.so; http { ... more_clear_headers Server; ... } |