Nginx 컴파일 설치

신동수·2024년 2월 24일

Server

목록 보기
6/9

먼저 시작하기 전 패키지 설치 대신 소스 설치를 해야하는 이유

다양한 의견이 있지만 운영 업무를 하며 느낀 것들
1. 해당 버전이 EOS 되었을 때 버전 변경을 빠르게 할 수 있다.
2. 루트 권한 없이 지정한 사용자를 통해 서비스 운영이 가능하다.
3. 의존성 문제 해결

설치

1. 소스에서 NGINX 컴파일 및 설치

C/C++ 컴파일러, PCRE(Perl 호환 정규식), Zlib 압축 라이브러리 및 OpenSSL(SSL 지원으로 Nxing을 실행하려는 경우) 다음 명령을 실행하여 컴퓨터에 패키지를 설치

# 필요한 패키지 설치
yum -y install gcc gcc-c++ make zlib-devel pcre-devel openssl-devel

2. Nginx 설치

# 필요한 패키지 설치
cd /data/web/nginx
wget http://nginx.org/download/nginx-1.24.0.tar.gz
tar xfz nginx-1.24.0.tar.gz
cd nginx-1.24.0
# nginx 컴파일 시 경로 지정
% ./configure --user=web \
--group=web \
--prefix=/data/web/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/data/web/nginx/conf/nginx.conf \
--error-log-path=/data/web/nginx/logs/error.log \
--http-log-path=/data/web/nginx/logs/access.log \
--pid-path=/data/web/nginx/run/nginx.pid \
--lock-path=/data/web/nginx/run/nginx.lock \
--with-http_ssl_module \ #여기서 부터는 안함
--with-pcre

# 소스에서 설치
% make
% make install



설치가 완료되면 위와 같이 확인할 수 있으며 기본적인 구조는 위와 같이 확인할 수 있음.

Nginx 서비스 관리

Nginx 프로세스를 관리하려면 아래의 명령을 사용해야 한다.

# nginx 명령어

# nginx 버전 및 compiler 또는 configure 표시
/sbin/nginx -V
# nginx 도움말
/sbin/nginx -h
# nginx 설정파일 확인
/sbin/nginx -t
# nginx 시작
/sbin/nginx
# nginx 중지
/sbin/nginx -s stop
# nginx 재기동
/sbin/nginx -s reload 
# systemd 스크립트를 통해 nginx 데몬 프로세스를 관리
vi /etc/systemd/system/nginx.service
# /etc/systemd/system/nginx.service 파일 내용
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/data/web/nginx/run/nginx.pid
ExecStartPre=/sbin/nginx -t
ExecStart=/sbin/nginx
ExecReload=/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Nginx Install
링크에서 컴파일 시 더 다양한 옵션을 줄 수 있음

# nginx systemd 파일 생성 후 아래 명령어로 데몬을 관리
systemctl daemon-reload
systemctl start nginx
systemctl stop nginx
systemctl status nginx


아래는 systemctl 명령어를 통해 nginx 프로세스를 확인한 결과이다.

미완성으로 아래 링크 참고
http://www.chlux.co.kr/bbs/board.php?bo_table=board02&wr_id=98&page=1
http://nginx.org/download/nginx-1.24.0.tar.gz
https://opentutorials.org/module/384/4511
http://nginx.org/en/docs/configure.html
https://server-talk.tistory.com/301
https://data-wiki.tistory.com/2
https://ko.linux-console.net/?p=6844 참고
https://medium.com/@jyson88/nginx-source-compile-%EA%B5%AC%EC%84%B1-936f728cd088 참고
https://wangtak.tistory.com/10 참고

profile
조금씩 성장하는 DevOps 엔지니어가 되겠습니다. 😄

2개의 댓글

comment-user-thumbnail
2025년 1월 13일

Wow, this article was a lifesaver! I was struggling with compiling and installing NGINX from source, especially handling dependencies and configuring SSL support. The step-by-step breakdown really helped me understand the process better.

I especially appreciated the part about managing NGINX services—having all the commands in one place made things so much easier. Definitely bookmarking this for future reference!

For anyone also setting up NGINX on Ubuntu, I found another great resource on installing OpenCart on Ubuntu 20.04 with NGINX—it might come in handy if you're working with e-commerce setups!

답글 달기
comment-user-thumbnail
2025년 1월 23일

This guide was a lifesaver! I had been struggling to compile Nginx from source and was confused about all the different dependencies and configuration options. The step-by-step instructions here made everything much clearer. I especially appreciated the details on managing Nginx with systemd – it really helped me streamline my setup.

If you're looking for a smooth way to install Nginx on Rocky Linux, I highly recommend checking out this Install Nginx on Rocky Linux 9 guide. It’s a great resource that helped me a lot. Thanks for the great write-up!

답글 달기