기타

Nginx.conf 간결정리

더the덕 2022. 2. 21. 09:55

Nginx의 설명

nginx는 하나의 master process와 하나 이상의 worker process로 구성되어있다.

Master process: -> configuration file을 읽고 실행하며, worker process들을 관리

Worker process: ->유저가 요청한 request에 대한 실제 작업을 수행

[Directive]

nginxmodule로 구성되며 moduleconfiguration file에 적힌 directive로 제어하며

directive에는 simple directiveblock directive가 존재

 

-simple directive: name parameter space로 구분되고 semicolon(;)로 끝난다.

-block directive: semicolon 대신에 { }로 둘러 쌓인 additional arguments로 끝난다.

 

->block directive 들 중 { } 안에 다른 directives 들이 들어간 경우는 context라고 하며
(event, http, server, location directive
가 존재함)

 

 

 

simple directive

user : Linux 시스템의 어느 usernginx 서버를 소유하고 동작 시킬지를 기술

worker_processes : 몇 개의 thread가 사용 될지 정의되며 (CPU 코어수게 맞추는 것이 권장됨.)

<nginx 프로세스 실행 가능 수 이며 실질적인 웹 서버 역할을 실시>

error_log : 에러 로그를 어느 위치의 어느 파일에 기록할지 정의

pid : process ID를 어느 위치의 어느 파일에 기록할지 선언

 

block directive

1.event context

work_connection : worker process 하나당 몇 개의 connectioin 을 처리할지 정의

 

2.http context

 

include /etc/nginx/mime.types : mime.types 파일을 읽어 드린다.

default_type : mime 타입 설정

log_format main : 액세스 로그 형식 설정

sendfile : sendfile api를 사용할지 설정

keepalive_timeout : 접속 시 커넥션을 몇 초 동안 유지할지에 대한 설정

include /etc/nginx/conf.d/*.conf –> /etc/nginx/conf.d 디렉토리 아래 있는 .conf 파일을 모두 읽음

 

 

3.server / location context

 

nginx configuration파일에는 적어도 하나의 server directive가 있어야 하며

nginx가 요청을 처리 할 때 가장 먼저요청을 처리할 virtual server을 선택한다.

Server configuration block에는 요청을 listen을 특정 ip 주소와 포트, domain socketpath매핑

location directive를 이용하여 nginx요청 URI에 따라 다른 서버로 트래픽을 전송할 수 있다.

location안에 다른 location directive로도 설정가능

 

<설명>

80포트로 요청이 올 시 해당 location 을 확인하여 어떻게 처리 할지 설정

1.location / 의 요청이 오면 8080포트로 리버스 프록시 응답

2.location /test 의 요청이 오면 /data/에서 파일을 찾은 후 응답해줌

3.location/test2의 요청이 오면 /data2/경로에서 파일을 찾은 후 응답해줌

 

참조 페이지 : https://nginx.org/en/docs/beginners_guide.html#conf_structure

 

 

'기타' 카테고리의 다른 글

20201 OWASP TOP 10 문제점 및 예방 방법  (0) 2022.02.21
tomcat -> server.xml 기본 구성요소  (0) 2022.02.21
파일 디스크립터  (0) 2022.02.21
Centos7 su vs sudo  (0) 2022.02.21
Centos7 보안설정  (0) 2022.02.21