我正在使用Django 3.0.6,并希望停靠我的项目。一切都工作正常,除了静态文件。静态文件是完全加载时,我运行我的项目正常。但是,停靠后,他们没有加载,并抛出一个404错误。我的项目布局如下:
├── nginx
│ ├── Dockerfile
│ └── nginx.conf
├── src
├── applications
├── configuration
│ ├── asgi.py
│ ├── __init__.py
│ ├── __pycache__
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── Dockerfile
├── manage.py
├── requirements.txt
├── static
│ ├── build
│ ├── images
│ └── vendors
└── templates
settings.py:
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
停靠文件:
FROM python:3.6
ENV PYTHONUNBUFFERED 1
ENV SRC_DIR=/var/www/project/src
RUN mkdir -p $SRC_DIR
WORKDIR $SRC_DIR
ADD ./requirements.txt $SRC_DIR/requirements.txt
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
ADD . $SRC_DIR
docker-compose.yml:
version: '3'
services:
web:
build:
context: ./src
dockerfile: Dockerfile
command: bash -c "python manage.py makemigrations && python manage.py migrate && gunicorn --bind 0.0.0.0:8000 -w 4 configuration.wsgi"
env_file: ./src/.environment
volumes:
- ./src:/var/www/project/src
- ./src/static:/var/www/project/src/static
ports:
- 8000:8000
depends_on:
- db
nginx:
build:
context: ./nginx
dockerfile: Dockerfile
ports:
- 80:80
volumes:
- ./src:/var/www/project/src
- ./src/static:/var/www/project/src/static
depends_on:
- web
nginx.conf:
upstream view {
server web:8000;
}
server {
listen 80;
location / {
proxy_pass http://view;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /static/ {
autoindex on;
alias /var/www/project/src/static;
}
}
我不知道是什么问题,请帮我解决这个问题。
1条答案
按热度按时间stszievb1#
我正常安装了nginx,并用docker安装了其他的,它现在正在工作。