참고
Nginx 컨테이너 생성
NOTE
Nginx 내부 설정을 커스텀하기 위해 Dockerfile로 내가 작성한 nginx.conf 파일을 nginx 컨테이너에 넣어준다!
Nginx - 설치
NOTE
Docker run
docker run --name web -p 80:80 -dt nginx
Bash
복사
Docker file
#Dockerfile
FROM nginx:latest
COPY nginx.conf /etc/nginx/nginx.conf
CMD ["nginx", "-g", "daemon off;"]
EXPOSE 80
Shell
복사
nginx.conf 파일을 설정하기 위해 COPY값으로 기본 설정파일을 덮어쒸움
Nginx - 설정파일
NOTE
•
블럭으로 감싸져있으면 block 디렉티브
•
안감싸져 있으면 simple 디렉티브
nginx.conf 코드
상단 설정
NOTE
worker_process
•
몇 개의 worker_process를 생성할 것인지를 지정하는 지시어
•
현재는 1인데, 모든 요청을 하나의 프로세스로 실행한다는 의미
•
보통 auto로 둔다.
error_log
•
로그 레벨을 설정하는 지시어
•
로그 레벨은 debug | info | notice | warn | error | crit 가 있다.
pid
•
nginx의 마스터 프로세스 id정보가 저장된다.
http 블록
NOTE
Nginx는 /etc/nginx/conf.d 패키지에 .conf 확장자의 파일을 작성하면 자동으로 설정에 추가된다!
include를 사용해서 설정파일을 분리해서 관리한다!
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
upstream docker-server {
server server:8080;
}
server {
listen 80;
server_name localhost;
location / {
# ...
}
}
# ...
include /etc/nginx/conf.d/*.conf;
}
Bash
복사
server 블록
NOTE
Nginx 내부 설정을 커스텀하기 위해 Dockerfile로 내가 작성한 nginx.conf 파일을 nginx 컨테이너에 넣어준다!
•
서버 기능을 설정하는 블록
•
어떤 주소:포트로 요청을 받을지 결정
listen : port 설정
server_name : 주소 설정
location 블록
NOTE
요청 URI를 분석하여 세부 설정!