Docker nginx ssl 错误

Docker nginx ssl 错误

当我抬起容器时,出现以下错误:

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/09/04 23:08:42 [emerg] 1#1: cannot load certificate "/etc/ssl/5master.crt": BIO_new_file() failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/ssl/5master.crt','r') error:2006D080:BIO routines:BIO_new_file:no such file)
nginx    | nginx: [emerg] cannot load certificate "/etc/ssl/5master.crt": BIO_new_file() failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/ssl/5master.crt','r') error:2006D080:BIO routines:BIO_new_file:no such file)
nginx exited with code 1

尽管在 DockerFile 中,我复制了命令调用文件夹中的证书文件。

nginx 配置:

server {
    listen              80;
    listen              443 ssl;
    server_name         5master.com;
    ssl_certificate     /etc/ssl/5master.crt;
    ssl_certificate_key /etc/ssl/5master.key;
}

Docker文件:

FROM python:3.8

WORKDIR /usr/src/app
ADD . /usr/src/app

COPY requirements.txt ./

RUN pip install --upgrade pip
RUN pip install -r requirements.txt

COPY . .

EXPOSE 5000

CMD ["uwsgi", "app.ini"]
COPY nginx.conf /etc/nginx/conf.d
COPY 5master.crt /etc/ssl/5master.crt
COPY 5master.key /etc/ssl/5master.key

docker-compose:

version: "3.8"
services:
  api:
    build: .
    restart: "always"
    environment:
      FLASK_APP: run.py
    volumes:
      - .:/usr/src/app


  nginx:
    build: ./nginx
    container_name: nginx
    restart: always
    volumes:
      - /application/static/:/static
    depends_on:
      - api
    ports:
      - "80:80"
      - "443:443"

答案1

您正在复制容器中的证书文件和 nginx 配置api。您需要将容器中的文件挂载nginx为卷。

  nginx:
    build: ./nginx
    container_name: nginx
    restart: always
    volumes:
      - /application/static/:/static
      - ./nginx.conf:/etc/nginx/conf.d/nginx.conf
      - ./5master.crt:/etc/ssl/5master.crt
      - ./5master.key:/etc/ssl/5master.key
    depends_on:
      - api
    ports:
      - "80:80"
      - "443:443"

相关内容