Nginx는 'nginx.conf' 설정 파일에서 Nginx 서버에 관한 다양한 설정을 정할 수 있다. 파일 안에는 Directives와 Context이 모여 Configuration을 만든다. 계층 순서대로 Directives부터 Configuration까지 알아보도록 하자.
Directives
Directives는 config 파일 안의 지시어다. 파일의 가장 기본 단위이자 서버가 실행하는 명령어라 생각하면 된다. Directives는 크게 두 가지로 나뉜다.
- Single Directives
- Block Directives
말 뜻대로 Directives는 한 줄로 구성할 수 있고, 중괄호를 사용해 섹션 혹은 블록처럼 구성할 수 있다. 같은 내용의 설정이 많이 필요한 경우 Directives를 블록으로 구성해야할 필요가 있을 것이다. 예시를 보자.
user nobody;
error_log logs/error.log notice;
worker_processes 1;
다음 설정들은 Single Directives를 이용해 구성한 설정이다.
user nobody; # a directive in the 'main' context
events {
# configuration of connection processing
}
http {
# Configuration specific to HTTP and affecting all virtual servers
server {
# configuration of HTTP virtual server 1
location /one {
# configuration for processing URIs starting with '/one'
}
location /two {
# configuration for processing URIs starting with '/two'
}
}
}
event, http, server, location 모두 Block Directives로 구성한 것이다. 각각의 블록들은 설정의 문맥인 Context를 설정한다. Block Directives는 단순히 명령어라기 보다는 규칙 집합을 만드는 것과 같다. 따라서 자연스럽게 Context를 생성하는 것이다.
Context
'nginx.conf' 파일 내에서 지시어가 효력을 발휘하는 '영역'이다. 프로그래밍 언어의 Scope(변수 범위)와 아주 비슷하다.
- http 블록 안에 Directive를 적으면 해당 Directive는 웹 서비스 전체에 적용된다.
- server 블록 안에 Directive를 적으면 해당 Directive는 특정 도메인에만 적용된다.
- location 블록 안에 Directive를 적으면 해당 Directive는 특정 URL 경로에만 적용된다.
여러 글이 모여 문단을 만들고 그 속에 문맥이 있듯, 여러 개의 Directive가 모여 설정에 대한 '문맥'을 만든다고 보면 된다.
이러한 Context에는 계층이 있다. 위의 예시를 다시 가져오자.
user nobody; # a directive in the 'main' context
events {
# configuration of connection processing
}
http {
# Configuration specific to HTTP and affecting all virtual servers
server {
# configuration of HTTP virtual server 1
location /one {
# configuration for processing URIs starting with '/one'
}
location /two {
# configuration for processing URIs starting with '/two'
}
}
}
http 블록 안에는 server와 location이 있고, server안에 location이 있다. 각각의 Context는 계층을 가지고 있으며, 상위 계층에서 적용한 설정은 하위 계층에 전부 적용 된다.
Configurations
Configuration은 Nginx 서버 설정 전체이자 상태를 의미한다. Nginx 서버는 'nginx.conf' 파일을 통해 설정을 명시하는데, Configuration은 파일 전체 혹은 서버 설정값 전체를 의미한다.
예를 들어 nginx 파일에서 Content Caching 기능을 사용하기 위해 디스크와 메모리를 설정했다면 이 상태가 해당 Nginx 서버의 Configuration이 된다. (그냥 nginx.conf 파일값이라 보면 된다!)
[출처]
https://docs.nginx.com/nginx/admin-guide/basic-functionality/managing-configuration-files/
Create NGINX Plus and NGINX Configuration Files | NGINX Documentation
Create NGINX Plus and NGINX Configuration Files NGINX and NGINX Plus use a text‑based configuration file, by default named nginx.conf. NGINX Plus: default location is /etc/nginx for Linux or /usr/local/etc/nginx for FreeBSD. NGINX Open Source: location d
docs.nginx.com
