Answer the question
In order to leave comments, you need to log in
Why doesn't Django + AWS & Nginx work in production?
On localhost, my AWS setup works and all media files are stored and downloaded as well as taken from the S3 bucket.
settings.py
AWS_ACCESS_KEY_ID = 'some_key'
AWS_SECRET_ACCESS_KEY = 'F'
AWS_STORAGE_BUCKET_NAME = 'my_bucket'
AWS_S3_SIGNATURE_VERSION = 's3v4'
AWS_S3_FILE_OVERWRITE = False
AWS_DEFAULT_ACL = None
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
/* HERE THE PATH TO MY AWS BUCKET
================================*/
location /media {
proxy_pass https://diasmart-media-static.s3.amazonaws.com/; // diasmart-media-static это bucket name
}
/* ============END============= */
location /static {
alias /root/DiaStore/src/assets;
}
location / {
proxy_pass http://127.0.0.1:8001;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
add_header Access-Control-Allow-Origin *;
}
}
Answer the question
In order to leave comments, you need to log in
Hello, is NGINX running on EC2? If so, then create a role in Amazon IAM for EC2 instance with read permission on this bucket. After that, when you access the nginx server via ssh, you must execute the curl command and the picture should be downloaded without any AWS_ACCESS_KEY.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question