• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    미해결

nginxproxy 설정 부분에서 질문있습니다!

21.10.03 00:02 작성 조회수 249

0

안녕하세요. 강사님 정말 좋은 강의 만들어주셔서 너무 감사드립니다.
 
다름이 아니라 강의를 듣던 중 nginx.conf 설정 부분에서 upstream 으로 실행중인 container 를 지칭하는 부분에 대해 이해가 되지 않는 부분이 있어 질문드립니다!
 
질문 내용은
1. 다음과 같은 환경에서
- nginxproxy, react를 띄우는 docker-compose.yaml
version: "3"

services:
  nginxproxy:
    depends_on:
      - client
    image: nginx:latest
    ports:
      - "80:80"
      - "443:443"
    restart: always
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./certbot-etc:/etc/letsencrypt
      - ./myweb:/usr/share/nginx/html
    container_name: nginxproxy

  certbot:
    depends_on:
     - nginxproxy
     - client
    image: certbot/certbot
    container_name: certbot
    volumes:
      - ./certbot-etc:/etc/letsencrypt
      - ./myweb:/usr/share/nginx/html
    command: certonly --webroot --webroot-path=/usr/share/nginx/html --email example@gamil.com --agree-tos --no-eff-email --keep-until-expiring -d example.com -d www.example.com

  front:
    restart: always
    build:
      context: /home/ubuntu/client
      dockerfile: Dockerfile
    ports:
      - "4000:80" # if want direct access
    container_name: client
- Front의 DockerFile로 실행되는 서버는 80포트로 요청을 받고 있습니다.
 
- 80 포트 /client 으로 들어오는 요청 front:4000 으로 전달하고 있는 nginx.proxy
upstream docker-client {
        server front:4000;
    }


server {
        listen 80;
        server_name example.com www.example.com;

        location ~ /.well-known/acme-challenge {
                allow all;
                root /usr/share/nginx/html;
                try_files $uri =404;
                #try_files $uri /index.tsx;
        }

        # Redirection
        location / {
                return 301 https://$host$request_uri;
        }
    }

server {
        listen 443 ssl;
        server_name example.com www.example.com;

        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
        include /etc/letsencrypt/options-ssl-nginx.conf;
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

        proxy_connect_timeout 1d;
        proxy_send_timeout 1d;
        proxy_read_timeout 1d;

        location /client/ {
            proxy_pass         http://docker-client;
            proxy_http_version 1.1;
            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;
            proxy_set_header   X-Forwarded-Host $server_name;
            proxy_set_header   X-Forwarded-Proto $scheme;
       }

2. client Browser 에서 http://example.com 으로 요청했을 때

3. 예상되는 결과는 아래와 같습니다.

---------------

4. 그러나 결과적으로 정상적으로 요청이 처리되고 있는데

제가 놓치고 있는 부분이 어디인지 알 수있을까요?

 

+ upstream 부분을 아래로 바꾸어도 정상동작합니다

upstream docker-client {
        server front;
    }

 

 

답변 1

답변을 작성해보세요.

0

안녕하세요. 우선은 본 질문/답변은 영상에 대한 문의라서요. 개별적인 이슈나 개인의 코드에 대한 이슈등에 대해서는 양해를 부탁드려요. 본 강의가 평생 강의라서, 각 개인적인 이슈/코드를 평생 봐드리는 것이 무리가 있어서요. 또 개인의 코드는 개인 외의 다른 사람이 체크를 하려면, 한참 시간이 걸려서요. 솔직히 굉장히 긴 설정인데, 그 설정 중에, 어떤 부분이 문제가 되는지를 누군가 한눈에 바로 이 부분이 문제입니다. 라고 이야기하는 무리가 있어서요. 

정확하고 꼼꼼하게 제가 볼 수 있을 수는 없는데, 가볍게는 제가 잘 이해했는지 모르겠지만 왜 내부 front 서버에 접속이 안되냐???? 이것 같고, 글쎄요. front:4000 이라면, 해당 front 서버 도커의 내부 설정이 4000번 포트를 내부 포트로 수신받아서 정상적으로 처리할 수 있는지를 먼저 보시는 것도 가볍게 체크해볼만한 포인트가 아닐까 생각합니다.

감사합니다.