Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建django、gunicorn和nginx的docker映像时出错_Django_Docker_Nginx_Docker Compose_Gunicorn - Fatal编程技术网

创建django、gunicorn和nginx的docker映像时出错

创建django、gunicorn和nginx的docker映像时出错,django,docker,nginx,docker-compose,gunicorn,Django,Docker,Nginx,Docker Compose,Gunicorn,我无法获取静态文件。我尝试过各种设置和目录配置等等,但它们只是显示为404 应用程序的文件夹结构如下所示 . ├── config │ └── nginx │ └── conf.d │ └── local.conf ├── docker-compose.yml ├── Dockerfile ├── aggre │ ├── aggre │ └── manage.py | └── static ├── requirements.txt Setting

我无法获取静态文件。我尝试过各种设置和目录配置等等,但它们只是显示为404

应用程序的文件夹结构如下所示

.
├── config
│   └── nginx
│       └── conf.d
│           └── local.conf
├── docker-compose.yml
├── Dockerfile
├── aggre
│   ├── aggre
│   └── manage.py
|   └── static
├── requirements.txt
Settings.py看起来像

STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR),'static']
STATIC_ROOT = os.path.join(os.path.dirname(os.path.dirname(BASE_DIR)), 'static')
Dockerfile

FROM python:3.6
ENV PYTHONUNBUFFERED 1
RUN mkdir -p /opt/services/django/src
WORKDIR /opt/services/django/src
COPY requirements.txt /tmp/
RUN pip install --requirement /tmp/requirements.txt
COPY . /tmp/
COPY . /opt/services/django/src
RUN python aggre/manage.py collectstatic --no-input  # <-- here
CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait"
EXPOSE 8000
ADD . /opt/services/django/src
CMD ["gunicorn", "--chdir", "aggre", "--bind", ":8000", "aggre.wsgi:application"]
local.conf

server {
    listen 80;
    server_name ***.***.io;

    location / {
        proxy_pass http://djangoapp:8000;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }
    location /static {
        alias /opt/services/django/static;
    }
}
我正在使用 **

docker组装--已组装

应用程序已成功启动,但未加载静态文件。 我越来越

“/opt/services/django/src/static/js/bootstrap.js”失败(2:无此错误) 文件或目录) **

基本目录

BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(文件))


我没有发现加载静态文件失败的地方。

您是否有机会在
settings.py
中关闭
DEBUG
?如果启用调试,Django不提供静态文件off@prithajnathDEBUG仅在settings.py中为TRUE。您是否碰巧在
settings.py中关闭了
DEBUG
?如果启用调试,Django不提供静态文件off@prithajnath调试仅在settings.py中为TRUE
server {
    listen 80;
    server_name ***.***.io;

    location / {
        proxy_pass http://djangoapp:8000;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }
    location /static {
        alias /opt/services/django/static;
    }
}