Docker Compose Nginx内部服务器错误

2024-04-25 11:45:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在我的docker compose文件中的nginx上托管一个flask应用程序,但当我这样做时,它会给我一个Internal Server error

以下是一些重要文件:

docker-compose.yml

version: "3.8"

services:
  th3pl4gu3:
    container_name: portfolix
    build: ./
    networks:
      - portfolix_net
    ports:
      - 8084:8084
    restart: always

  server:
    image: nginx:1.17.10
    container_name: nginx
    depends_on:
      - th3pl4gu3
    volumes:
      - ./reverse_proxy/nginx.conf:/etc/nginx/nginx.conf
    ports:
      - 80:80
    networks:
      - portfolix_net

networks:
  portfolix_net:
    name: portfolix_network
    driver: bridge

nginx.conf:

server {
listen 80;

location / {
    include uwsgi_params;
    uwsgi_pass th3pl4gu3:8084;
}
}

烧瓶Dockerfile

# Using python 3.8 in Alpine
FROM python:3.8-alpine3.11

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app

# Dependencies for uWSGI
RUN apk add python3-dev build-base linux-headers pcre-dev && pip install -r requirements.txt && apk update

# In case bash is needed
#RUN apk add --no-cache bash

# Tell the port number the container should expose
EXPOSE 8084

# Run the command
ENTRYPOINT ["uwsgi", "app.ini"]

app.ini

[uwsgi]
module = run:app

master = true
processes = 5

http-socket = 0.0.0.0:8084
chmod-socket = 660
vacuum = true

die-on-term = true

现在,当我在没有nginx服务的情况下运行docker compose时,它可以工作,但我希望它在nginx服务器上运行。知道我为什么会出现内部服务器错误吗


Tags: thecomposedockernametrueappnetcontainer
1条回答
网友
1楼 · 发布于 2024-04-25 11:45:40

我通过以下docker compose解决了这个问题:

version: "3.8"

services:
  th3pl4gu3:
    container_name: portfolix
    build: ./
    networks:
      - portfolix_net
    expose:
      - 8084
    restart: always

  server:
    image: nginx:1.17.10
    container_name: nginx
    depends_on:
      - th3pl4gu3
    volumes:
      - ./reverse_proxy/nginx.conf:/etc/nginx/nginx.conf
    ports:
      - 8084:80
    networks:
      - portfolix_net

networks:
  portfolix_net:
    name: portfolix_network
    driver: bridge

问题是我的8084:8084

相关问题 更多 >