본문 바로가기
컴퓨터/Linux

Centos7 환경에서 nginx 컴파일 설치 및 systmctl 등록하기

by 토크미 2023. 1. 18.

nginx 컴파일 설치하기

 

1. nginx 설치에 필요한 의존성 패키지 사전 설치 하기

[root@localhost ~]# yum -y install gcc gcc-c++ wget
[root@localhost nginx-1.14.0]# yum -y install openssl openssl-devel

 

2. 필요한 nginx 버전으로 확인 (현 시점 최신 버전은 1.23.3)

 

최신버전 경로 : http://nginx.org/download/

 

3. wget 으로 필요한 nginx 버전 다운로드

[root@localhost src]# wget http://nginx.org/download/nginx-1.20.1.tar.gz

4. 압축 해제

[root@localhost src]# tar -zxvf nginx-1.20.1.tar.gz

5. 압축 해제 경로로 이동

[root@localhost src]# cd nginx-1.20.1/

6. 컴파일 진행

[root@localhostnginx-1.14.0]#./configure

 

7. 컴파일 버전 설치 진행

[root@localhost nginx-1.14.0]# make
[root@localhost nginx-1.14.0]# make install

8. 설치된 경로로 이동

[root@localhost nginx-1.14.0]#cd /usr/local/nginx/sbin

9. nginx 서비스 시작

 

[root@localhost nginx-1.14.0]#./nginx

10. nginx 서비스 동작 여부 확인

[root@localhost nginx-1.14.0]# ps aux |grep nginx

 

nginx systemctl에 등록하여 서비스 시작시키기

1. 컴파일된 nginx에는 /etc/systemd/system/multi-user.target.wants/ 디렉토리에 nginx.service 파일이 없으므로 새 파일을 생성합니다.

[root@localhost nginx-1.14.0]#vim /usr/lib/systemd/system/nginx.service

아래 내용을 그대로 붙여 넣습니다.

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

 

2, 기존의 nginx 서비스를 종료 시킵니다.

[root@localhost nginx-1.14.0]# pkill -9 nginx

3. systemctl 데몬을 설정 정보를 갱신합니다.

[root@localhost nginx-1.14.0]#systemctl daemon-reload

4.재부팅후 nginx가 자동으로 재시작 되도록 설정한다.

[root@localhost nginx-1.14.0]# systemctl enable nginx.service

5. systemctl 명령어로 nginx를 시작 시킵니다.

[root@localhost nginx-1.14.0]#systemctl start nginx