質問編集履歴
1
大幅な情報の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,28 +2,214 @@
|
|
2
2
|
|
3
3
|
Wagtail(Django)の静的ファイルをAmazon S3互換のオブジェクトストレージ、MinIOに格納しようとしています。
|
4
4
|
|
5
|
-
`python manage.py
|
5
|
+
`python manage.py collectstatic` で静的ファイルをMinIOに格納したあと、Djangoを`python manage.py runserver`で立ち上げた際に静的ファイルが表示されません。
|
6
6
|
|
7
7
|
### 発生している問題・エラーメッセージ
|
8
8
|
|
9
|
-
ブラウザのコンソールを見ると、静的ファイルの
|
9
|
+
ブラウザのコンソールを見ると、返ってきた静的ファイルのMIME typeが`text/html`であると表示されています。
|
10
10
|
|
11
|
-
|
11
|
+
#### ブラウザのエラーメッセージその1
|
12
12
|
|
13
|
+
```
|
14
|
+
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:9090/minio/wagtail/wagtail/css/huidetang.css".
|
15
|
+
```
|
16
|
+
|
17
|
+
#### ブラウザのエラーメッセージその2
|
18
|
+
|
19
|
+
```
|
20
|
+
Cross-Origin Read Blocking (CORB) blocked cross-origin response http://localhost:9090/minio/wagtail/wagtail/css/huidetang.css with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.
|
21
|
+
```
|
22
|
+
|
23
|
+
CSSのURLに直リンクで飛ぶとMinIOのHTMLインターフェイスが表示されています。
|
24
|
+
|
13
25
|
### 該当のソースコード
|
14
26
|
|
15
27
|
リポジトリは[huideyeren/huidetang](https://github.com/huideyeren/huidetang)にあります。
|
16
28
|
|
17
|
-
#### localhost.py
|
29
|
+
#### localhost.py(抜粋)
|
18
30
|
|
31
|
+
```
|
19
|
-
|
32
|
+
if "AWS_STORAGE_BUCKET_NAME" in os.environ:
|
33
|
+
# Add django-storages to the installed apps
|
34
|
+
INSTALLED_APPS = INSTALLED_APPS + [
|
35
|
+
"storages",
|
36
|
+
"wagtail_storages",
|
37
|
+
]
|
20
38
|
|
39
|
+
# https://docs.djangoproject.com/en/stable/ref/settings/#default-file-storage
|
40
|
+
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
|
41
|
+
|
42
|
+
AWS_STORAGE_BUCKET_NAME = os.environ["AWS_STORAGE_BUCKET_NAME"]
|
43
|
+
|
44
|
+
# Disables signing of the S3 objects' URLs. When set to True it
|
45
|
+
# will append authorization querystring to each URL.
|
46
|
+
AWS_QUERYSTRING_AUTH = False
|
47
|
+
|
48
|
+
# Do not allow overriding files on S3 as per Wagtail docs recommendation:
|
49
|
+
# https://docs.wagtail.io/en/stable/advanced_topics/deploying.html#cloud-storage
|
50
|
+
# Not having this setting may have consequences such as losing files.
|
51
|
+
AWS_S3_FILE_OVERWRITE = False
|
52
|
+
|
53
|
+
# Default ACL for new files should be "private" - not accessible to the
|
54
|
+
# public. Images should be made available to public via the bucket policy,
|
55
|
+
# where the documents should use wagtail-storages.
|
56
|
+
AWS_DEFAULT_ACL = "private"
|
57
|
+
|
58
|
+
# We generally use this setting in production to put the S3 bucket
|
59
|
+
# behind a CDN using a custom domain, e.g. media.llamasavers.com.
|
60
|
+
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#cloudfront
|
61
|
+
if "AWS_S3_CUSTOM_DOMAIN" in os.environ:
|
62
|
+
AWS_S3_CUSTOM_DOMAIN = os.environ["AWS_S3_CUSTOM_DOMAIN"]
|
63
|
+
|
64
|
+
# When signing URLs is enabled, the region must be set.
|
65
|
+
# The global S3 endpoint does not seem to support signed URLS.
|
66
|
+
# Set this only if you will be using signed URLs.
|
67
|
+
if "AWS_S3_REGION_NAME" in os.environ:
|
68
|
+
AWS_S3_REGION_NAME = os.environ["AWS_S3_REGION_NAME"]
|
69
|
+
|
70
|
+
# This settings lets you force using http or https protocol when generating
|
71
|
+
# the URLs to the files. Set https as default.
|
72
|
+
# https://github.com/jschneier/django-storages/blob/10d1929de5e0318dbd63d715db4bebc9a42257b5/storages/backends/s3boto3.py#L217
|
73
|
+
AWS_S3_URL_PROTOCOL = os.environ.get("AWS_S3_URL_PROTOCOL", "https:")
|
74
|
+
|
75
|
+
AWS_S3_ENDPOINT_URL = os.environ["AWS_S3_ENDPOINT_URL"]
|
76
|
+
|
77
|
+
AWS_LOCATION = "wagtail"
|
78
|
+
|
79
|
+
AWS_S3_USE_SSL = False
|
80
|
+
AWS_S3_SECURE_URLS = False
|
81
|
+
|
82
|
+
STATICFILES_STORAGE = "storages.backends.s3boto3.S3StaticStorage"
|
83
|
+
STATIC_URL = "http://localhost:9090/minio/wagtail/%s/" % (AWS_LOCATION)
|
84
|
+
```
|
85
|
+
|
86
|
+
#### docker-compose.yml
|
87
|
+
|
88
|
+
```yaml
|
89
|
+
version: '3.7'
|
90
|
+
services:
|
91
|
+
nginx:
|
92
|
+
image: nginx:latest
|
93
|
+
volumes:
|
94
|
+
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
|
95
|
+
ports:
|
96
|
+
- 80:80
|
97
|
+
depends_on:
|
98
|
+
- backend
|
99
|
+
- frontend
|
100
|
+
postgres:
|
101
|
+
image: postgres:12
|
102
|
+
restart: always
|
103
|
+
environment:
|
104
|
+
POSTGRES_USER: postgres
|
105
|
+
POSTGRES_PASSWORD: password
|
106
|
+
ports:
|
107
|
+
- '5432:5432'
|
108
|
+
volumes:
|
109
|
+
- db-data:/var/lib/postgresql/data:cached
|
110
|
+
backend:
|
111
|
+
build:
|
112
|
+
context: backend
|
113
|
+
dockerfile: Dockerfile
|
114
|
+
volumes:
|
115
|
+
- ./backend:/app/:cached
|
116
|
+
environment:
|
117
|
+
PYTHONPATH: .
|
118
|
+
DATABASE_URL: 'postgresql://postgres:password@postgres:5432/postgres'
|
119
|
+
AWS_S3_CUSTOM_DOMAIN: 'localhost:9090/minio/wagtail'
|
120
|
+
AWS_S3_ENDPOINT_URL: 'http://minio:9000/'
|
121
|
+
AWS_STORAGE_BUCKET_NAME: 'wagtail'
|
122
|
+
AWS_ACCESS_KEY_ID: 'huidetang'
|
123
|
+
AWS_S3_REGION_NAME: 'us-east-1'
|
124
|
+
AWS_SECRET_ACCESS_KEY: 'jsYIDsqqIt9JShu'
|
125
|
+
AWS_S3_URL_PROTOCOL: 'http:'
|
126
|
+
depends_on:
|
127
|
+
- "postgres"
|
128
|
+
- "minio"
|
129
|
+
frontend:
|
130
|
+
build:
|
131
|
+
context: frontend
|
132
|
+
dockerfile: Dockerfile
|
133
|
+
stdin_open: true
|
134
|
+
volumes:
|
135
|
+
- './frontend:/app:cached'
|
136
|
+
- './frontend/node_modules:/app/node_modules:cached'
|
137
|
+
environment:
|
138
|
+
- NODE_ENV=development
|
139
|
+
minio:
|
140
|
+
image: minio/minio:latest
|
141
|
+
ports:
|
142
|
+
- 9090:9000
|
143
|
+
volumes:
|
144
|
+
- ./minio/data:/data
|
145
|
+
- ./minio/export:/export
|
146
|
+
- ./minio/config:/root/.minio
|
147
|
+
- ./minio/policies:/policies
|
148
|
+
environment:
|
149
|
+
MINIO_ACCESS_KEY: 'huidetang'
|
150
|
+
MINIO_SECRET_KEY: 'jsYIDsqqIt9JShu'
|
151
|
+
entrypoint:
|
152
|
+
- /bin/sh
|
153
|
+
- -c
|
154
|
+
command:
|
155
|
+
- "mkdir -p /data/.minio.sys/buckets; cp -r /policies/* /data/.minio.sys/; cp -r /export/* /data/; /usr/bin/minio server /data"
|
156
|
+
createbuckets:
|
157
|
+
image: minio/mc
|
158
|
+
depends_on:
|
159
|
+
- minio
|
160
|
+
entrypoint: >
|
161
|
+
/bin/sh -c "
|
162
|
+
until (/usr/bin/mc config host add wagtail http://minio:9000 huidetang jsYIDsqqIt9JShu) do echo '...waiting...' && sleep 1; done;
|
163
|
+
/usr/bin/mc mb wagtail/wagtail;
|
164
|
+
/usr/bin/mc admin user add wagtail wagtail jsYIDsqqIt9JShu;
|
165
|
+
exit 0;
|
166
|
+
"
|
167
|
+
volumes:
|
168
|
+
db-data:
|
169
|
+
|
170
|
+
```
|
171
|
+
|
172
|
+
#### policy.json(MinIO)
|
173
|
+
|
174
|
+
```json
|
175
|
+
{
|
176
|
+
"Version": "2012-10-17",
|
177
|
+
"Statement": [
|
178
|
+
{
|
179
|
+
"Sid": "AllowUserManageBucket",
|
180
|
+
"Effect": "Allow",
|
181
|
+
"Principal": "*",
|
182
|
+
"Action": [
|
183
|
+
"s3:ListBucket",
|
184
|
+
"s3:GetBucketLocation",
|
185
|
+
"s3:ListBucketMultipartUploads",
|
186
|
+
"s3:ListBucketVersions"
|
187
|
+
],
|
188
|
+
"Resource": "arn:aws:s3:::wagtail"
|
189
|
+
},
|
190
|
+
{
|
191
|
+
"Sid": "AllowUserManageBucketObjects",
|
192
|
+
"Effect": "Allow",
|
193
|
+
"Principal": "*",
|
194
|
+
"Action": [
|
195
|
+
"s3:GetObject",
|
196
|
+
"s3:PutObject",
|
197
|
+
"s3:DeleteObject"
|
198
|
+
],
|
199
|
+
"Resource": "arn:aws:s3:::wagtail/*"
|
200
|
+
}
|
201
|
+
]
|
202
|
+
}
|
203
|
+
|
204
|
+
```
|
205
|
+
|
206
|
+
|
21
207
|
### 試したこと
|
22
208
|
|
23
|
-
静的ファイルの設定
|
209
|
+
静的ファイルの設定は最初以下のようにしていました。
|
24
210
|
|
25
211
|
```python
|
26
|
-
STATICFILES_STORAGE = 'storages.backends.s3boto3.
|
212
|
+
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
|
27
213
|
```
|
28
214
|
|
29
215
|
### 補足情報(FW/ツールのバージョンなど)
|