Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure Nginx for aws s3 static and media files

I am using aws s3 for static and media files for my django app. Gunicorn and Nginx are being used for application and proxy server.

Nginx setup:

server {
    listen 80;
    server_name sitename.com;

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/SiteNameDjango/myproject/myproject.sock;
    }
}

Since I am using aws s3 for my static and media files, how should I configure Nginx for my static location? Or there's no need to configure for the static and media files?

If it helps, here is the Django project settings for aws s3:

STATICFILES_LOCATION = 'static'
MEDIAFILES_LOCATION = 'media'
STATICFILES_STORAGE = 'myproject.custom_storages.StaticStorage'
DEFAULT_FILE_STORAGE = 'myproject.custom_storages.MediaStorage'
AWS_STORAGE_BUCKET_NAME = "django-bucket"
AWS_S3_CUSTOM_DOMAIN = AWS_STORAGE_BUCKET_NAME + ".s3.amazonaws.com"
STATIC_URL = "https://" + AWS_STORAGE_BUCKET_NAME + ".s3.amazonaws.com/"
MEDIA_URL = STATIC_URL + "media/"
ADMIN_MEDIA_PREFIX = STATIC_URL + "admin/"

Eg url:

https://django-bucket.s3.amazonaws.com/media/user_image/1497598249_49.jpeg
like image 227
Kakar Avatar asked Jun 22 '17 03:06

Kakar


People also ask

Does S3 use nginx?

You can use both NGINX Open Source and NGINX Plus as the gateway to S3 or a compatible object store. To use NGINX Open Source, start with the official NGINX image from Docker Hub and the Dockerfile we provide on GitHub.

Where does AWS store static files?

In AWS, Simple Storage Service (S3) is used to store any kind of data blobs on an object storage back end with unlimited capacity.


1 Answers

In case of S3, nginx is not responsible for serving static and media files and you no need to configure anything.

like image 121
Zada Zorg Avatar answered Nov 11 '22 09:11

Zada Zorg