Я не могу заставить NGINX (что я считаю виновником) работать с django -хранилищами при загрузке медиа-файла. Он получит stati c файлы из моего хранилища S3, но просто отказывается публиковать в нем сообщения. Всякий раз, когда изображение загружается на сайт, я получаю NGINX 500 Internal Server Error. Он работает с приложением runserver django по умолчанию, и я не уверен, что приводит к сбою. Все это выполняется в контейнере docker. Вот что у меня есть:
Настройки, показывающие, как настроены хранилища
AWS_STORAGE_BUCKET_NAME = 'sitename-staticfiles'
AWS_S3_REGION_NAME = 'us-east-1'
AWS_ACCESS_KEY_ID= 'access_key'
AWS_SECRET_ACCESS_KEY= 'secret_key'
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
AWS_QUERYSTRING_AUTH = False
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
AWS_DEFAULT_ACL = None
STATICFILES_LOCATION = 'static'
STATICFILES_STORAGE = 'custom_storages.StaticStorage'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static', 'sitename')]
MEDIAFILES_LOCATION = 'media'
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'
custom_storages.py
from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage
class StaticStorage(S3Boto3Storage):
location = settings.STATICFILES_LOCATION
class MediaStorage(S3Boto3Storage):
location = settings.MEDIAFILES_LOCATION
nginx .conf
user nobody;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name sitename.com localhost;
location / {
include uwsgi_params;
uwsgi_param SCRIPT_NAME /;
uwsgi_pass unix:///var/tmp/sitename.sock;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
#include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;
}
uwsgi.ini
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = %d
# Django's wsgi file
module = sitename.wsgi
# the virtualenv (full path)
# home = /
#socket=:8000
# http = 0.0.0.0:8000
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 4
# the socket (use the full path to be safe
socket = /var/tmp/sloopsnoop.sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
# clear environment on exit
vacuum = true
docker -compose.yaml
version: '3.7'
services:
web:
build: ./app
entrypoint: ./entrypoint-prod.sh
volumes:
- ./app/:/usr/src/app/
- static_volume:/usr/src/app/static/
- media_volume:/usr/src/app/media/
ports:
- 8085:80
env_file:
- ./.env.dev
depends_on:
- db
db:
image: postgres:12-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
- POSTGRES_DB=sitename_db_dev
volumes:
postgres_data:
static_volume:
media_volume: