업데이트

업데이트

저는 Docker 컨테이너를 사용하여 웹 앱을 호스팅하고 있습니다. MySQL, 플라스크, Nginx라는 세 가지 주요 컨테이너가 있습니다. 처음 두 개는 예상대로 작동하고 후자는 docker-compose 시작 시 오류가 표시되지 않으므로 제대로 작동하는 것 같습니다.

Nginx 컨테이너 초기화 출력:

nginx  | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
nginx  | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
nginx  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
nginx  | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
nginx  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginx  | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
nginx  | /docker-entrypoint.sh: Configuration complete; ready for start up
nginx  | 2022/04/07 13:09:13 [notice] 1#1: using the "epoll" event method
nginx  | 2022/04/07 13:09:13 [notice] 1#1: nginx/1.21.6
nginx  | 2022/04/07 13:09:13 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6) 
nginx  | 2022/04/07 13:09:13 [notice] 1#1: OS: Linux 4.19.130-boot2docker
nginx  | 2022/04/07 13:09:13 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
nginx  | 2022/04/07 13:09:13 [notice] 1#1: start worker processes
nginx  | 2022/04/07 13:09:13 [notice] 1#1: start worker process 21

Nginx 도커파일

# Dockerfile-nginx
FROM nginx:latest
# Nginx will listen on this port
# EXPOSE 80
# Remove the default config file that
# /etc/nginx/nginx.conf includes
RUN rm /etc/nginx/conf.d/default.conf
# We copy the requirements file in order to install
# Python dependencies
COPY nginx.conf /etc/nginx/conf.d/

배포 후 컨테이너 및 해당 포트:

CONTAINER ID   IMAGE             COMMAND                  CREATED          STATUS                 PORTS                               NAMES
bffffcfe2f70   sc_server_nginx   "/docker-entrypoint.…"   14 seconds ago   Up 13 seconds          0.0.0.0:80->80/tcp                  nginx
a73d958c1407   sc_server_flask   "uwsgi app.ini"          9 hours ago      Up 9 hours             8080/tcp                            flask
d273db5f80ef   mysql:5.7         "docker-entrypoint.s…"   21 hours ago     Up 9 hours (healthy)   0.0.0.0:3306->3306/tcp, 33060/tcp   mysql

저는 Nginx 서버를 처음 사용하기 때문에 초보자 오류일 수도 있습니다. 호스트 시스템의 80 포트에서 소켓을 통해 트래픽을 WSGI 컨테이너로 리디렉션하는 docker의 80으로 모든 트래픽을 리디렉션하려고 합니다.

나는 다음과 같은 Nginx 구성을 사용하고 있습니다(내 생각에는 그다지 멋진 구성은 아닙니다):

server {
  listen 80;
  location / {
    include uwsgi_params;
    uwsgi_pass flask:8080;
  }
}

보시다시피 서버는 포트 80에서 수신 대기하고 소켓을 통해 uwsgi_pass flask:8080;앱을 호스팅하는 WSGI 컨테이너로 모든 트래픽을 리디렉션합니다.

그러나 브라우저에 127.0.0.1:80 또는 0.0.0.0:80을 입력할 때마다 연결이 거부됩니다. 방화벽이 배포되어 있지 않으므로 포트 80이 다운되는 데 문제가 없는 것 같습니다.

이것은 초기화 및 배포 매개변수가 표시된 내 app.ini 구성 파일입니다.

[uwsgi]
wsgi-file = wsgi.py
; This is the name of the variable
; in our script that will be called
callable = app
; We use the port 8080 which we will
; then expose on our Dockerfile
socket = :8080
; Set uWSGI to start up 4 workers
processes = 4
threads = 2
master = true
chmod-socket = 660
vacuum = true
die-on-term = true

또한 docker-compose.yml도 포함합니다(도움이 될 것 같습니다).

docker-compose.yml

services:
  flask:
    build: ./flask
    container_name: flask
    restart: always
    environment:
      - APP_NAME=MyFlaskApp
      - YOURAPPLICATION_SETTINGS=docker_config.py
    expose:
      - 8080
    depends_on:
      mysql:
          condition: service_healthy
  mysql:
    image: mysql:5.7
    container_name: mysql
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD:
      MYSQL_DATABASE:
      MYSQL_USER:
      MYSQL_PASSWORD:
    volumes:
      - ./db/init.sql:/data/application/init.sql
    healthcheck:
      test: mysql -u -p --database -e "show tables;"
      interval: 3s
      retries: 5
      start_period: 30s
  nginx:
    build: ./nginx
    container_name: nginx
    restart: always
    depends_on:
      - mysql
      - flask
    ports:
      - "80:80"

누구든지 도와줄 수 있나요?

업데이트

Wireshark를 사용하여 루프백 인터페이스를 스캔하여 0.0.0.0:80에 대한 서버의 응답을 확인했으며(포트 80에 문제가 있는 것으로 의심됩니다) 다음과 같은 페이로드를 얻습니다.

와이어샤크

관련 정보