Nginx

Linux에서 Nginx 1.10.1 설치하고 nginx_status 설정하기

강철지그·2016년 8월 20일·조회 19,009

1. 설치

1.10.1 설치 파일은 https://nginx.org/download/nginx-1.10.1.tar.gz 입니다.

1.1. configure

# ./configure --prefix=/app/nginx-1.10.1
checking for OS
 + Linux 2.6.32-279.el6.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for gcc builtin 64 bit byteswap ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + md5: using system crypto library
  + sha1: using system crypto library
  + using system zlib library

  nginx path prefix: "/app/nginx-1.10.1"
  nginx binary file: "/app/nginx-1.10.1/sbin/nginx"
  nginx modules path: "/app/nginx-1.10.1/modules"
  nginx configuration prefix: "/app/nginx-1.10.1/conf"
  nginx configuration file: "/app/nginx-1.10.1/conf/nginx.conf"
  nginx pid file: "/app/nginx-1.10.1/logs/nginx.pid"
  nginx error log file: "/app/nginx-1.10.1/logs/error.log"
  nginx http access log file: "/app/nginx-1.10.1/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

1.2. make

# make
make -f objs/Makefile
make[1]: Entering directory `/Downloads/nginx/nginx-1.10.1'
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
                -o objs/src/core/nginx.o \
                src/core/nginx.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
                -o objs/src/core/ngx_log.o \
                src/core/ngx_log.c



sed -e "s|%%PREFIX%%|/app/nginx-1.10.1|" \
                -e "s|%%PID_PATH%%|/app/nginx-1.10.1/logs/nginx.pid|" \
                -e "s|%%CONF_PATH%%|/app/nginx-1.10.1/conf/nginx.conf|" \
                -e "s|%%ERROR_LOG_PATH%%|/app/nginx-1.10.1/logs/error.log|" \
                < man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/Downloads/nginx/nginx-1.10.1'

1.3. make install

# make install
make -f objs/Makefile install
make[1]: Entering directory `/Downloads/nginx/nginx-1.10.1'
test -d '/app/nginx-1.10.1' || mkdir -p '/app/nginx-1.10.1'
test -d '/app/nginx-1.10.1/sbin' \
                || mkdir -p '/app/nginx-1.10.1/sbin'
test ! -f '/app/nginx-1.10.1/sbin/nginx' \
                || mv '/app/nginx-1.10.1/sbin/nginx' \
                        '/app/nginx-1.10.1/sbin/nginx.old'


make[1]: Leaving directory `/Downloads/nginx/nginx-1.10.1'

1.4. 기동

다음과 같은 프로세스가 실행됩니다.

# ps -ef | grep nginx
root     29872     1  0 08:58 ?        00:00:00 nginx: master process ./nginx
nobody   29873 29872  0 08:58 ?        00:00:00 nginx: worker process
root     29875 19769  0 08:58 pts/0    00:00:00 grep nginx

2. nginx_status 설정을 추가

        location /nginx_status {
            stub_status on;
            access_log off;
            allow 127.0.0.1;
            deny all;
        }

기동 결과입니다.

nginx: [emerg] unknown directive "stub_status" in /app/nginx-1.10.1/conf/nginx.conf:49

이유는...

configure 시에 "--with-http_stub_status_module" 옵션이 빠졌기 때문입니다.

처음에 아래와 같이 configure 후에 컴파일하면 잘 됩니다.

./configure --prefix=/app/nginx-1.10.1 --with-http_stub_status_module

자, 이제 nginx_status 화면 결과를 볼까요?

# curl http://127.0.0.1:80/nginx_status
Active connections: 1
server accepts handled requests
 28644 28644 32733
Reading: 0 Writing: 1 Waiting: 0

 총 7가지 항목에 대한 결과값을 확인할 수 있습니다. 차례대로 설명드리면..

  1. Active Connections
  2. total accepted connections
  3. total handled connections (보통 2번과 동일합니다)
  4. number of and handles requests
  5. Reading : nginx reads request header
  6. Writing : nginx reads request body, processes request, or writes response to a client
  7. Waiting : keep-alive connections, actually it is active

댓글 2

로그인 후 댓글을 남길 수 있습니다.

  • 혀뇽뇽이혀뇽뇽이· 2016년 8월 25일
    플러스버전이 아닌이상, nginx_status는 현재 연결된 connection및 request정보만 실시간으로 제공된다는 제약이 있죠.
  • 강철지그강철지그· 2016년 8월 27일
    zero1320/ 그건 참 아쉬운 점이네요. 일반 버전에서도 디테일하게 볼 방법이 없을까요?