2024. 7. 26. 09:33ㆍWEB/NGINX
# nginx.conf
텍스트 기반의 구성 파일로 해당 파일 내부에 설정된 값들을 통해 nginx가 튜닝되고 실행되게 됨
https://docs.nginx.com/nginx/admin-guide/basic-functionality/managing-configuration-files/
Creating NGINX Plus and NGINX Configuration Files | NGINX Documentation
Creating NGINX Plus and NGINX Configuration Files Understand the basic elements in an NGINX or NGINX Plus configuration file, including directives and contexts. NGINX and NGINX Plus are similar to other services in that they use a text‑based configurati
docs.nginx.com
https://nginx.org/en/docs/ngx_core_module.html
Core functionality
Core functionality Example Configuration user www www; worker_processes 2; error_log /var/log/nginx-error.log info; events { use kqueue; worker_connections 2048; } ... Directives Syntax: accept_mutex on | off; Default: accept_mutex off; Context: events If
nginx.org
→ 해당 Document를 참조하여 작성
1. 기본 INFO
구성 파일은 지시문과 해당 매개변수로 구성이 되며 각 지시문은 각각의 세미콜론으로 끝맺음
→ simple directive
지시문 중 특정 지시문은 관련 지시문을 그룹화하는 컨테이너 역할을 하며 {}로 묶음
→ block directive
/etc/nginx/conf.d 디렉터리에 기능별로 파일들을 분할 하고 nginx.conf 파일에 include 지시문을 이용하여 해당 파일들의 내용을 참조하도록 하는 것이 운영하는데 용이함
context라는 몇 가지 최상위의 지시문(지시어 블록)은 다양한 트래픽 유형에 적용되는 지시문을 그룹화함
지시어는 모듈에 의해 활성화되기 때문에 모듈이 제공하는 지시어들은 해당 지시어 블록 안에서만 사용 가능
- events - 일반 연결 처리 관련 지시문
- http - HTTP 트래픽 관련 지시문
- mail - main 트래픽 관련 지시문
- stream - TCP / UDP 관련 트래픽 관련 지시문
ex)
user oracle;
worker_processes 1;
include conf.d/http;
include conf.d/stream;
event {
...
}
2. 각 지시문 내용 분석
nginx 최초 설치 시 확인 가능한 default 값의 nginx.conf 파일을 바탕으로 분석
- simple directive
user oracle;
error_log /var/log/nginx/error.log crit;
worker_processes auto;
pid /run/nginx.pid;
user
OS의 어떤 사용자가 nginx 서버를 동작시킬 것인지 작성
error_log
error log를 설정하는 부분으로 파일 위치와 로깅 레벨을 설정할 수 있음
worker_processes
nginx가 사용할 Thread의 개수를 작성하는 부분으로 CPU 코어 수에 맞추는 것이 일반적
pid
nginx pid 적인 파일의 위치와 파일 명을 설정

- block directive
① events
연결 처리에 영향을 미치는 지시문이 지정되는 구성 파일 콘텍스트를 제공
events {
worker_connections 1024;
worker_aio_requests 32;
multi_accept off;
debug_conntection 127.0.0.1;
#use method;
}
worker_connections
nginx의 process 하나당 몇 개의 connnection을 처리할 것인지 설정
worker_aio_requests
epoll 연결 처리 방법과 함께 aio를 사용하는 경우 단일 작업자 process에 대한 처리되지 않은 비동기 I/O 작업의 최댓값을 설정
multi_accept
off 인 경우 worker process는 한 번에 하나의 새로운 연결을 수락
on 인 경우 worker process는 한 번에 모든 새로운 연결을 수락
debug_connection
선택한 client 연결에 대한 디버깅 로그를 활성화 그 외 연결은 error_log 지시문에서 설정한 로깅 수준을 사용
디버깅된 연결은
- 호스트 이름을 사용하여 연결 지정
- Unix 도메인 소켓(1.3.0, 1.2.1)을 사용하여 연결할 경우 'unix:'를 사용하여 연결 지정
- IPv4 / IPv6 주소 / 네트워크를 사용하여 연결 지정
use
사용할 연결 처리를 지정
일반적으로 nginx 자체적으로 가장 효율적인 방법을 사용하므로 명시적으로 지정할 필요 없음

'WEB > NGINX' 카테고리의 다른 글
nginx & WAS 연동 (0) | 2024.07.30 |
---|---|
nginx Load Balancing (0) | 2024.07.29 |
nginx ssl 설정 (0) | 2024.07.29 |
nginx.conf (2) (0) | 2024.07.29 |
nginx 설치 (0) | 2024.07.25 |