본문으로 건너뛰기

Nginx 설치 방법은 무엇인가요?

💡 요약 정리

  • Nginx는 러시아 개발자가 만든 고성능 웹서버로 메모리와 성능이 우수합니다
  • 2002년부터 시작되어 최근 사용하는 곳이 급속히 증가하고 있습니다
  • 리눅스 멀티코어 서버에서 Apache 대비 성능 차이가 크게 나타납니다
  • 소스 컴파일 설치 후 init 스크립트를 생성하여 서비스로 등록합니다
Nginx logo

엔진엑스 nginx는 러시아 개발자(Igor Sysoev)가 혼자서 만든 프로젝트이지만, 메모리와 성능이 좋아 입소문으로 많이 사람들이 알게 되었습니다

2002년부터 시작되어 최근 사용하는 곳이 급속히 증가하고 있으며, 성능은 접속자가 어느정도 이상 되고 다양한 사이트가 운영되면 차이가 많이 나게됩니다.

서버가 리눅스일, 멀티코어일 경우 엔진엑스와 아파치의 차이가 많이 나게됩니다.

NGINX의 공식 설치 문서는 아래의 URL을 통해서 접근 할 수 있습니다.

http://nginx.org/en/docs/install.html

1. 다운로드

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

2. 압축해제

[root@localhost nginx]# tar zfvx nginx-1.4.0.tar.gz

3. nginx 필요 패키지 설치

[root@localhost src]# yum install gcc pcre-devel bzip2-devel openssl-devel

4. Nginx 설치

[root@localhost nginx]# mkdir -p /tmp/nginx/proxy
[root@localhost nginx]# mkdir -p /tmp/nginx/fcgi
[root@localhost nginx]# mkdir -p /tmp/nginx/client

[root@localhost nginx]# ./configure --prefix=/home/nginx --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --error-log-path=/home/nginx/log/error.log --http-log-path=/home/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client/ --http-proxy-temp-path=/tmp/nginx/proxy/ --http-fastcgi-temp-path=/tmp/nginx --http-scgi-temp-path=/tmp/nginx --http-uwsgi-temp-path=/tmp/nginx --with-http_realip_module --with-http_ssl_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_perl_module --with-http_image_filter_module --with-http_xslt_module --with-http_dav_module --with-http_flv_module --with-http_random_index_module --with-http_secure_link_module

[root@localhost nginx-1.0.0]# make -j4
[root@localhost nginx-1.0.0]# make install

5. Nginx 실행스크립트 생성

init 스크립트를 생성하고 서비스 등록합니다

[root@localhost nginx-1.0.0]# vi /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /home/nginx/conf/nginx.conf
# pidfile:     /home/nginx/logs/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/home/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest || return $?
    stop
    start
}

reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac
[root@localhost nginx-1.4.0]# chmod 755 /etc/rc.d/init.d/nginx
[root@localhost nginx-1.4.0]# /etc/rc.d/init.d/nginx status
[root@localhost nginx-1.4.0]# chkconfig --add nginx
[root@localhost nginx-1.4.0]# chkconfig nginx on
[root@localhost nginx-1.4.0]# service nginx start

6. Nginx 시작

[root@localhost nginx-1.4.0]#  /etc/init.d/nginx restart

문제가 해결되지 않았나요?

궁금하신 사항은 언제든지 1:1 문의게시판으로 문의해 주세요.

문의 시 포함 정보:

  • 카페24 아이디
  • 서비스 ID: 서버호스팅 서비스 ID
  • 서버 OS: CentOS / Ubuntu 등
  • Nginx 버전: nginx -v 명령 실행 결과
  • 에러 로그: /home/nginx/log/error.log 내용
  • 문의 내용: Nginx 설치 및 설정 관련 문의 사항