Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- Dag
- prometheus
- 오블완
- RAG
- Python
- Redshift
- airflow
- docker
- spark
- SQL
- pySpark
- airflow설치
- aiagent
- BigQuery
- Streamlit
- dockercompose
- grafana
- 설치
- kafka
- javascript
- vectorDB
- jmx-exporter
- MSA
- milvus
- amazonlinux
- hadoop
- 루프백주소
- sparkstreaming
- metadabatase
- ubuntu
Archives
- Today
- Total
데이터 노트
[Nginx] Amazon Linux EC2에서 nginx 서버 정보 제거를 위한 모듈 설정 본문
배경
Superset을 EC2 상에서 도커를 활용해 빌드한 상황.
보안 테스트를 위해 Superset이 연결되지 않았을 때 에러 테스트 등을 진행했는데, 헤더 값에 Nginx + 버전 정보가 담겨있어
이를 제거 하기 위한 작업을 진행하게 되었다.
작업
- nginx Server 헤더 정보 내 버전 정보만 삭제하기 위해서는 server_tokens만 추가하면 된다.
sudo vi /etc/nginx/nginx.conf
http {
server_tokens off;
...
}
-> 그럼 'server : nginx 1.22.1' 과 같은 모습이 'server : nginx'로만 뜬다.
- Server 헤더 내 nginx 자체를 완전히 없애려면 more_set_headers 설정이 필요한데,
이를 설정하기 위해서는 NGINX 모듈인 ngx_http_headers_more_filter_module이 필요하다.
http {
server_tokens off;
more_set_headers "Server: myServer";
...
}
- Debian/Ubuntu에서 설치 시,
sudo apt-get install nginx-extras
- CentOS/RHEL에서 설치 시,
sudo yum install nginx-mod-http-headers-more
- Amazon Linux는 해당 모듈을 지원하지 않기 때문에, nginx 동적 모듈로 컴파일해서 적용해 주어야한다.
cd /usr/local/src
# headers-more 모듈을 다운로드
sudo wget https://github.com/openresty/headers-more-nginx-module/archive/v0.34.tar.gz
# 다운로드한 모듈 압축 해제
sudo tar -zxvf v0.34.tar.gz
# Nginx 소스를 다운로드 (1.22.1 버전 예시)
sudo wget http://nginx.org/download/nginx-1.22.1.tar.gz
# 압축 해제
sudo tar -zxvf nginx-1.22.1.tar.gz
cd nginx-1.22.1
# 현재 Nginx의 컴파일 설정 확인
nginx -V
# 확인한 설정 값을 가지고 (configure arguments) 모듈 재컴파일
NGINX_CONFIGURE_OPTIONS=$(nginx -V 2>&1 | grep 'configure arguments')
sudo ./configure $NGINX_CONFIGURE_OPTIONS --add-dynamic-module=/usr/local/src/headers-more-nginx-module-0.34
# 동적 모듈로 컴파일
sudo make modules
# 컴파일된 모듈 nginx 모듈 디렉토리로 복사 (modules 디렉토리 없으면 생성 후 작업)
sudo cp objs/ngx_http_headers_more_filter_module.so /etc/nginx/modules
- NGINX_CONFIGURE_OPTIONS : 현재 설정 옵션을 저장하는 변수입니다.
- sed 's/configure arguments: //' : Nginx 설치 시의 설정 옵션 부분만 추출합니다.
- 추가적으로 난 해당 설정으로 컴파일 시, --with-cc-opt 설정이 자꾸 에러가 나서 빼고 컴파일을 진행했었고,
그래서 sed 's/--with-cc-opt='\\''-O2 -g.*//' 을 추가했었다.
-> --with-cc-opt에서 시작하는 디버깅 플래그(g)를 제거.
- nginx 설정 파일 내용 추가
# nginx.conf 파일 수정
load_module modules/ngx... # 추가
...
http {
...
more_set_headers "Server: myServer"; # 추가
}
...
- 적용을 위해 nginx 재기동
sudo systemctl restart nginx
sudo systemctl status nginx
트러블슈팅
- 이후 nginx 설정 파일 문법이 맞나 체크하면 자꾸 에러 발생
sudo nginx -t
nginx:[emerg] module "/etc/nginx/modules/ngx_http_headers_more_filter_module.so" is not binary compatible in /etc/nginx/nginx.conf : 2
- 원인이 무엇인지 엄청 찾아 해맸는데 결국 컴파일 할 때부터 문제였고, 옵션을 추가해주고 해결했다.
# --with-compat 추가 필요
sudo ./configure --with-compat $NGINX_CONFIGURE_OPTIONS --add-dynamic-module=/usr/local/src/headers-more-nginx-module-0.34
'Web' 카테고리의 다른 글
WS 와 WAS 의 차이 (0) | 2023.02.10 |
---|---|
[JavaScript] querySelector 과 querySelectorAll 의 차이 (0) | 2022.06.14 |
[JavaScript] 속성, 메소드, 생성자, 프로토타입 (0) | 2022.06.13 |