500服务器错误通过Whitenoise提供静态服务

时间:2019-12-05 18:33:46

标签: django docker whitenoise

对于其中的代码长度,我们深表歉意,我想确保为故障排除目的添加尽可能多的内容。

我有一个需要在生产环境中提供静态文件的Django应用程序,并且我选择了whitenoise,因为它A)是为实现此目的而构建的,而B)似乎是最简单的配置。我已经按照the documentationthis medium articlethis blog post中的步骤进行操作,但是仍然看到500个服务器错误。我没有比这更多的详细信息,我没有得到堆栈跟踪错误,并且页面仅显示500服务器错误。

我不知道自己在做错什么,以使其能够正常工作。我正在做什么与博客正在做什么之间的唯一区别是我的应用程序是在Docker容器中构建的。任何帮助将非常感激!

settings.py

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STAT = os.path.join(BASE_DIR, 'static')

DEBUG = False

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'audit_tool',
    'rest_framework',
    'crispy_forms',
    'bootstrap',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
]

WSGI_APPLICATION = 'audit_tool_app.wsgi.application'

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

# Automate compression by whitenoise
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

Dockerfile

# Pull official base image
FROM internal.site:11448/python:3.7.2

# Set env variables
ENV ALLOWED_HOSTS 0.0.0.0
ENV APP_PORT 0000

# Install dependencies
COPY pip /pip

RUN python3.7 -m pip install --no-cache-dir pip/* \
&& python3.7 -m pip install -U --index-url http://internal.com/repository/PythonPIP/simple --trusted-host internal.com gunicorn==19.3.0 lxml==4.3.3 pandas==0.25.1 numpy==1.15.4 psycopg2==2.8.4 whitenoise==4.1.4 uwsgi requests django-bootstrap-static

COPY . /app
WORKDIR /app

# Migrate
RUN python manage.py migrate

EXPOSE $APP_PORT
HEALTHCHECK CMD curl --fail http://localhost:$APP_PORT || exit 1

CMD ["sh", "-c", "gunicorn audit_tool_app.wsgi:application --bind 0.0.0.0:8001 --workers 3"] 

0 个答案:

没有答案