vendredi 9 août 2019

serving media files from a separate storage

my web works great, I can get the media files(images uploaded from others) show up and static files are served from digitalocean space. But I want the media files to be served from digital ocean as well. is it possible for one bucket to store both static and media files?

My settings.py

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
MEDIA_URL = '/media/'



AWS_ACCESS_KEY_ID = ''
AWS_SECRET_ACCESS_KEY = '
AWS_STORAGE_BUCKET_NAME = ''
AWS_S3_ENDPOINT_URL = ''
AWS_S3_OBJECT_PARAMETERS = {
    'CacheControl': '',
}
AWS_LOCATION = ''

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]
STATIC_URL = 'https://%s/%s/' % (AWS_S3_ENDPOINT_URL, AWS_LOCATION)
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

my directory looks like

project
    project
    app
    media
    static

I have

/etc/nginx/sites-avaliabe/myproject


server {
    server_name www.xx.com xx.com;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        alias /home/zz/xx;
    }

    location /media/ {
        root /home/zz/x;x
    }
    location / {
        include proxy_params;
        proxy_pass http://unix:/home/zz/x.xsock;
    }

with the above way static files operate the way I want so I did the same thing for the media files but with that media files won't be displayed....




Aucun commentaire:

Enregistrer un commentaire