部署django wagtail项目的media文件到AWS S3

首先在AWS S3上创建好IAM账号和存储桶BUCKET,增加属性

    "Statement": [
        {
          "Sid":"PublicReadForGetBucketObjects",
          "Effect":"Allow",
          "Principal": {
                "AWS": "*"
             },
          "Action":["s3:GetObject"],
          "Resource":["arn:aws:s3:::BUCKET-NAME/*"
          ]
        },
        {
            "Action": "s3:*",
            "Effect": "Allow",
            "Resource": [
                "arn:aws:s3:::BUCKET-NAME",
                "arn:aws:s3:::BUCKET-NAME/*"
            ],
            "Principal": {
                "AWS": [
                    "USER-ARN"
                ]
            }
        }
    ]
} ```
### * BUCKET-NAME,* USER-ARN记得修改为自己的。

### 然后在settings.py 或base.py(wagtail) 配置:
``` AWS_STORAGE_BUCKET_NAME = 'xxxxx'
AWS_ACCESS_KEY_ID = 'xxxxxxxx'
AWS_SECRET_ACCESS_KEY = 'xxxxxxxxx'
AWS_S3_CUSTOM_DOMAIN = 's3-ap-northeast-1.amazonaws.com/%s' % AWS_STORAGE_BUCKET_NAME ```

* 这里的AWS_S3_CUSTOM_DOMAIN可能不是相同的,可以自己上传个文件然后
然后看url规律修改。
### dev.py,production.py写上:
``` MEDIA_URL = "https://%s/" % AWS_S3_CUSTOM_DOMAIN
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' ```

你可能感兴趣的:(部署django wagtail项目的media文件到AWS S3)