[django]添加 nginx 时,我的 dockerized django 应用程序无法运行
· 收录于 2024-01-06 11:11:06 · source URL
问题详情
我正在尝试对我的 django 应用程序进行 docker 化,并尝试使用 nginx 为其提供服务。我不确定出了什么问题,但 nginx 重定向到正确的 URL,但 django 应用程序根本没有加载。
例如,如果我打开由 gunicorn 提供的 URL http://localhost:8000/cas/login/?service=http://localhost:8000/
,则应用程序可以正确加载。然而,当去 http://localhost:1337/
时,我会被重定向到 https://localhost/cas/login/?service=http://localhost/
,并显示无法连接。我不确定出了什么问题。任何指针将不胜感激。
docker-compose.yml
version: "4.0"
services:
db:
image: mariadb
ports:
- "3307:3306"
environment:
MYSQL_DATABASE: 'atshrd_db'
MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
volumes:
- ./data/mysql/dbb:/var/lib/mysql
app:
build: .
volumes:
- .:/django
ports:
- "8000:8000"
expose:
- "8000"
image: app:django
container_name: django_container
#command: python manage.py runserver 0.0.0.0:8000
command: sh -c "gunicorn --chdir /django/project --reload project.wsgi:application --bind 0.0.0.0:8000"
#command: gunicorn --bind 0.0.0.0:8000 --chdir /django/project --reload project.wsgi:application
depends_on:
- db
nginx:
build: ./nginx
volumes:
- ./project/hrd/static:/var/www/static
- ./project/hrd/media:/var/www/media
ports:
- 1337:80
depends_on:
- app
Docker文件
FROM python:3.9
ENV PYTHONUNBUFFERED 1
WORKDIR /django
RUN pip install --upgrade pip
COPY requirements.txt requirements.txt
COPY /project ./project
RUN pip install cmake
RUN pip install -r requirements.txt
RUN pip install opencv-python-headless
RUN pip install mediapipe tensorflow==2.11.0 tensorflow-io-gcs-filesystem==0.27.0
RUN pip install face-recognition
RUN pip install django_datatables_view
RUN pip install django_cron
RUN pip install dlib
RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 -y
EXPOSE 8000
nginx.conf
文件#upstream django_container {
# server app:8000;
#}
server {
listen 80;
location / {
proxy_pass http://app:8000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /media/ {
alias /var/www/media/;
}
# Django static
location /static/ {
alias /var/www/static/;
}
}
最佳回答
暂无回答