티스토리 뷰

반응형
  • "XXX" directive is not allowed here in...
    • nginx.conf 설정을 잘못된 파일에 작성하였을 경우에 확인할 수 있는 에러이다.
    • 내가 작성하려는 nginx.conf에 포함된 값 중 XXX에 해당하는 key의 위치가 잘못된 경우에 발생한다. 설정 파일을 확인하자!
  • host not found in upstream "호스트:포트"...
    • 해당 호스트 및 포트를 정말 찾지 못했을 경우에 확인할 수 있는 에러이다.
    • 대상 호스트가 UP 상태인지 확인하자. docker-compose를 사용한다면 depends_on 설정으로도 확인할 수 있을 듯

 

참고.

  • 아래는 docker-compose.yml에 nginx를 적용하는 예시이다.
  • docker-compose.yml
# docker-compose.yml
version: "3.7"
services:
  proxy:
    container_name: my-proxy
    image: nginx:latest
    volumes:
      - ${PWD}/nginx/nginx.conf:/etc/nginx/nginx.conf
    ports:
      - "8080:8080"
    depends_on:
      - test
  test:
    container_name: my-test
    image: my-test
  • nginx.conf
    • http.server.location.proxy_pass의 my-test는 http.upstream의 my-test를 가리킨다.
    • http.upstream.server의 test:3000은 docker-compose.yml의 서비스인 test를 나타낸다.
      내 경우, test 서비스인 my-test는 Dockerfile에 EXPOSE 3000을 명시하였다.
user  nginx;
worker_processes  1;
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;
    upstream my-test {
        server test:3000;
    }
    server {
        listen 8080;
        server_name localhost;
        location / {
            proxy_pass         http://my-test;
            proxy_redirect     off;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
    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;
}
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함