안녕하세요.

 

이번에는 요즘 많이 사용되고 있는 Nginx에 대해 설치 부터 튜닝까지 방법에 대해 진행해보겠습니다.

우선 그 첫번째로 Nginx 다운로드 및 설치하는 방법을 정리해봤습니다.

 

진행 순서는 1~8까지 가이드를 준비하고 있습니다.

  1. Nginx 설치 및 컴파일 방법_(모듈설치)
  2. Nginx 사용하는 옵션정리_proxy_pass
  3. Nginx 사용하는 옵션정리_upstream
  4. Nginx 사용하는 옵션정리_health-check
  5. Nginx 사용하는 옵션정리_sticky
  6. Nginx 사용하는 옵션정리_upstream, ip hash
  7. Nginx 사용하는 옵션정리_X-Forwarded-For
  8. Nginx 사용하는 옵션정리_php-fpm & zabbix 모니터링

 

 

Nginx 가 apache 보단 모듈화가 되있다 보니 사전에 설치해야 할 몇가지가 있네요.

아래 순서 대로 진행하셔보시고 컴파일시 필요한 부분만 사용하세요.

번거로우시면 패키지로 설치하셔도 되는데, 그럴경우 사용하지 않는 모듈까지 모두 설치가 진행되기에 보안이슈와 성능 저하가 발생할 수 있습니다.

번거롭더라도 사용하는 기능에 대해서만 설치 진행해보시길 권고드립니다.

 

1. nginx-1.10.2 버전 다운로드 및 설치 방법

- nginx 다운로드
  URL : http://nginx.org/en/download.html


- nginx 다운로드 버전 (3가지)
  NGINX는 안정버전(stable version), 개발버전(development version) 레거시버전(legacy version) 존재
  안정성을 고려해서 stable 버전으로 설치하길 권고
  
- wget 설치 및 압축 풀기
  wget http://nginx.org/download/nginx-1.10.3.tar.gz
  tar -xvf nginx-1.10.3.tar.gz 

 

2. nginx 사용시 필요 패키지 설치

 - pcre, pcre-devel 라이브러리 설치
  Nginx 컴파일하는데 펄 호환 정규표현식이 필요하다.
  Nginx의 재작성모듈과 HTTP 코어 모듈은 PCRE구문에 따르는 정규 표현식을 사용한다.
  yum install pcre pcre-devel
 - zlib zlib-devel 라이브러리 설치
  zlib 라이브러리는 개발자에게 압축 알고리즘을 제공한다. 
  yum install zlib zlib-devel
 - openssl openssl-devel 라이브러리 설치
  yum install openssl openssl-devel
 - nginx 모듈 확장 (github 로 echo module 샘플 다운로드)
  URL : http://wiki.nginx.org/3rdPartyModules
  wget https://github.com/agentzh/echo-nginx-module/archive/v0.45.zip;
  unzip v0.45.zip;

 

3. Nginx 컴파일 

  참고 URL : http://nginx.org/en/docs/install.html

  Nginx 컴파일 방법으로는 configure 실행 후 make && make install 해주면 됩니다.

  configure 에러가 나면 /objs/autoconf.err 파일을 참고하세요

 

- 컴파일 (이중에 필요한 것만 사용하세요.)

 ./configure --prefix=/etc/nginx 
--sbin-path=/usr/sbin/nginx 
--modules-path=/usr/lib64/nginx/modules 
--conf-path=/etc/nginx/nginx.conf 
--error-log-path=/설치경로/nginx/error.log 
--http-log-path=/설치경로/nginx/access.log 
--pid-path=/var/run/nginx.pid 
--lock-path=/var/run/nginx.lock 
--http-client-body-temp-path=/var/cache/nginx/client_temp 
--http-proxy-temp-path=/설치경로/nginx/proxy_temp 
--http-fastcgi-temp-path=/설치경로/nginx/fastcgi_temp 
--http-uwsgi-temp-path=/설치경로/nginx/uwsgi_temp 
--http-scgi-temp-path=/설치경로/nginx/scgi_temp
--user=nginx --group=nginx --with-file-aio --with-threads --with-ipv6 
--with-http_addition_module --with-http_auth_request_module 
--with-http_dav_module --with-http_flv_module 
--with-http_gunzip_module --with-http_gzip_static_module 
--with-http_mp4_module --with-http_random_index_module 
--with-http_realip_module --with-http_secure_link_module 
--with-http_slice_module --with-http_ssl_module 
--with-http_ssl_module 
--with-openssl=/경로/openssl-1.0.2k 
--with-http_stub_status_module 
--with-http_sub_module 
--with-http_v2_module 
--with-mail 
--with-mail_ssl_module 
--with-stream 
--with-stream_ssl_module 
--with-http_image_filter_module 
--with-http_xslt_module 

 

4. nginx 기동, 다운

1. 방법-1


- 기동 : nginx
- 즉시다운 : nginx -s stop   // 즉각적으로 nginx 를 다운한다.
- 정상다운 : nginx -s quit   // 정상적으로 nginx 를 종료시킨다
- 설정확인 : nginx -t        // 환경설정을 확인 한뒤 설정상 에러가 없는지 확인
2. 방법 -2


[/app/WEB/nginx]service nginx start  
Starting nginx:                                            [  OK  ]
[/app/WEB/nginx]service nginx restart
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
[/app/WEB/nginx]service nginx reload 
Reloading nginx:                                           [  OK  ]
[/app/WEB/nginx]service nginx status
nginx (pid  7807) is running...
[/app/WEB/nginx]service nginx stop  
Stopping nginx:                                            [  OK  ]

 

5. nginx 정상 확인 TEST
기본적으로 80 port 구동되느 방화벽 오픈되있으면 잘 떠있나 확인해보세요.

http://localhost:80 

+ Recent posts