예시
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name nginx-test;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
user = 사용자 지정 (기본값 - nginx)
user nginx;
worker_processes = 워커 프로세스 수 자동으로 설정
worker_processes auto;
error_log = 에러 로그 파일 경로 및 레벨 설정 => warn 이상 레벨만
error_log /var/log/nginx/error.log warn;
pid = Nginx PID 저장 경로 지정
pid /var/run/nginx.pid;
worker_connections = 단일 워커 프로세스당 최대 연결 수 지정 (기본값 - 1024)
events {
worker_connections 1024;
}
include = 포함시킬 외부 파일 지정
- MIME 타입 정의 파일 + 환경설정 파일
http {
include /etc/nginx/mime.types;
include /etc/nginx/conf.d/*.conf;
}
default_type = 웹 서버의 기본 Content-Type 지정
http {
default_type application/octet-stream;
}
log_format = 로그 포맷 지정
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
}
access_log = 접속 로그 경로 지정
http {
access_log /var/log/nginx/access.log main;
}
sendfile = 파일 전송 여부(sendfile 함수 사용 여부) 지정
sendfile on;
keepalive_timeout = 접속 시 연결 유지 시간 지정
keepalive_timeout 65;
server
server {
listen 80;
server_name nginx-test;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
- listen = 서버 포트 지정
- server-name = 서버 호스트명 지정
- root = 루트 경로 지정
- index = 초기 페이지 지정
- location = 특정 url에 대한 요청 처리 지정 (/ => 기본 경로)
※ try_files path1 path2 (final) = 일종의 URI 조건문
- path1 존재 => path1 반환
- path1 존재 X, path2 존재 => path2 반환
- path1 & path 2 존재 X, final 존재 => final 반환
- path1 & path 2 & final 존재 X => final 반환
※ $uri = URL에서 쿼리 문자열을 제외한 URI의 일부
ex) https://www.naver.com/map?param=value로 요청 => $uri = /map
댓글