https://xinet.kr/?p=3478

 

nginx version 숨기기 및 header 정보 숨기기 ( nginx remove the server header )

기본적으로 Nginx에서 nginx 버전 정보를 숨기는 것은 간단하게 해결 할수 있다기본값이 on 상태일때 값을 확인해 보면버전 정보를 숨기기 위해서는 nginx.conf 환경설정에서 server_tokens 값을 off 로 변

xinet.kr

 

기본적으로 Nginx에서 nginx 버전 정보를 숨기는 것은 간단하게 해결 할수 있다
기본값이 on 상태일때 값을 확인해 보면

 
 
 
 
 
Shell
 
1
2
3
4
5
[root@xinet nginx-1.21.6]# vi /usr/local/nginx/conf/nginx.conf
 
 
### version hide
    server_tokens on;

이렇게 구성할 경우 버전이 출력된다

 
 
 
 
 
Shell
 
1
2
3
4
5
6
7
8
9
10
11
[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 로 변경하면 된다

 
 
 
 
 
Shell
 
1
2
3
4
[root@xinet nginx-1.21.6]# vi /usr/local/nginx/conf/nginx.conf
 
### version hide
    server_tokens off;

nginx 재시작 후 확인

 
 
 
 
 
Shell
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[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 이용하면 된다

다운로드 후 모듈을 생성 후 추가해주면 된다

 
 
 
 
 
Shell
 
1
2
3
[root@xinet ~]# cd /usr/local/src/
 

기본 설치된 버전 없으면 다운로드 있으면 처음 설치 폴더로 가서 모듈 생성 및 복사

 
 
 
 
 
Shell
 
1
2
3
4
5
6
7
[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/

모듈이 복사가 되었으면 환경설정 값에  추가

 
 
 
 
 
Shell
 
1
2
3
4
5
6
7
8
9
[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 정보가 표시되지 않는다

 
 
 
 
 
Shell
 
1
2
3
4
5
6
7
8
9
10
11
12
13
[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 으로 설치된 환경이라면  해당 설치 후 모듈 추가된거 확인 후 이용하면 된다

 
 
 
 
 
Shell
 
1
2
3
yum -y install https://extras.getpagespeed.com/release-latest.rpm
 
yum -y install nginx-module-security-headers
 
 
 
 
 
Shell
 
1
2
3
4
5
6
7
load_module modules/ngx_http_headers_more_filter_module.so;
 
http {
    ...
    more_clear_headers Server;
    ...
}

 

'경로 및 정보' 카테고리의 다른 글

Teleport 관련 자료  (1) 2024.02.24
A deep dive into AWS S3 access controls – taking full control over your assets  (1) 2024.02.05
/.vscode/sftp.json  (0) 2023.11.19
Active Directory Basic 문제  (0) 2023.11.12
Fiddler 셋팅  (0) 2023.11.10
블로그 이미지

wtdsoul

,