본문 바로가기
Linux/CentOS

CentOS7 / nginx / mod_security / 컴파일 설치

by 데브믹서 2022. 8. 18.

mod_security 파일을 다운로드 받는다

$ wget https://www.modsecurity.org/tarball/2.9.1/modsecurity-2.9.1.tar.gz

 

압축을 해제한다

$ tar -zxvf modsecurity-2.9.1.tar.gz 

 

해당 경로로 이동한다 

$ cd modsecurity-2.9.1

$ ./configure --enable-standalone-module

$ make

 

nginx 다운로드 받기 (22-08-18일 기준으로 이것보다 바로 위버전은 컴파일시 에러 발생 - stable 버전 나와야 할듯)
https://nginx.org/en/download.html 


$ wget https://nginx.org/download/nginx-1.22.0.tar.gz

$ tar -zxvf nginx-1.22.0.tar.gz

$ cd nginx-1.22.0.tar.gz

$ ./configure --add-module=../modsecurity-2.9.1/nginx/modsecurity

$ make

$ make install

 

컴파일시 에러가 나서 gcc-c++ 설치함 ( g++: command not found )

$ yum install gcc-c++

 

컴파일중에 또다른 에러 발생 ( error: ‘ngx_http_connection_t’ has no member named ‘nfree’ )

공식 깃허브의 'ngx_http_modsecurity.c' 파일로 통채로 교체함 (아래는 원문파일) 
https://github.com/SpiderLabs/ModSecurity/blob/1bb2ffcd6b01bd492a0db48c55295421075d355f/nginx/modsecurity/ngx_http_modsecurity.c
https://raw.githubusercontent.com/SpiderLabs/ModSecurity/1bb2ffcd6b01bd492a0db48c55295421075d355f/nginx/modsecurity/ngx_http_modsecurity.c


이후 다시 
$ make
$ make install 로 설치 성공함 


컴파일해서 설치할 경우 nginx 경로는 /usr/local/nginx/sbin/nginx 쪽이 된다
nginx 실행하기
$ /usr/local/nginx/sbin/nginx;


이후 systemctl 에 nginx 서비스 등록함 (타 블로그 참조) 
ㄴ 등록할때는 프로세스를 ps -ef | grep nginx 통해서 끄고 
재시작 해야지 정상적으로 등록됨 


설치후 설정파일 경로
/usr/local/nginx/conf