質問編集履歴

1

大幅な情報の追加

2021/04/19 12:44

投稿

IosifHuideyeren
IosifHuideyeren

スコア12

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- `python manage.py runserver` で静的ファイルをMinIOに格納したあと、Djangoを`python manage.py runserver`で立ち上げた際に静的ファイルが表示されません。
9
+ `python manage.py collectstatic` で静的ファイルをMinIOに格納したあと、Djangoを`python manage.py runserver`で立ち上げた際に静的ファイルが表示されません。
10
10
 
11
11
 
12
12
 
@@ -14,11 +14,35 @@
14
14
 
15
15
 
16
16
 
17
- ブラウザのコンソールを見ると、静的ファイルのcontent-typeが`text/html`であると表示されています。
18
-
19
-
20
-
21
- 直リンクで飛ぶとMinIOHTMLインタフェイスが表示されています。
17
+ ブラウザのコンソールを見ると、返ってきた静的ファイルのMIME typeが`text/html`であると表示されています。
18
+
19
+
20
+
21
+ #### ブラウザエラメッセージその1
22
+
23
+
24
+
25
+ ```
26
+
27
+ Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:9090/minio/wagtail/wagtail/css/huidetang.css".
28
+
29
+ ```
30
+
31
+
32
+
33
+ #### ブラウザのエラーメッセージその2
34
+
35
+
36
+
37
+ ```
38
+
39
+ 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.
40
+
41
+ ```
42
+
43
+
44
+
45
+ CSSのURLに直リンクで飛ぶとMinIOのHTMLインターフェイスが表示されています。
22
46
 
23
47
 
24
48
 
@@ -30,11 +54,359 @@
30
54
 
31
55
 
32
56
 
33
- #### localhost.py
57
+ #### localhost.py(抜粋)
58
+
59
+
60
+
34
-
61
+ ```
62
+
35
-
63
+ if "AWS_STORAGE_BUCKET_NAME" in os.environ:
64
+
36
-
65
+ # Add django-storages to the installed apps
66
+
67
+ INSTALLED_APPS = INSTALLED_APPS + [
68
+
69
+ "storages",
70
+
71
+ "wagtail_storages",
72
+
73
+ ]
74
+
75
+
76
+
77
+ # https://docs.djangoproject.com/en/stable/ref/settings/#default-file-storage
78
+
79
+ DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
80
+
81
+
82
+
83
+ AWS_STORAGE_BUCKET_NAME = os.environ["AWS_STORAGE_BUCKET_NAME"]
84
+
85
+
86
+
87
+ # Disables signing of the S3 objects' URLs. When set to True it
88
+
89
+ # will append authorization querystring to each URL.
90
+
91
+ AWS_QUERYSTRING_AUTH = False
92
+
93
+
94
+
95
+ # Do not allow overriding files on S3 as per Wagtail docs recommendation:
96
+
97
+ # https://docs.wagtail.io/en/stable/advanced_topics/deploying.html#cloud-storage
98
+
99
+ # Not having this setting may have consequences such as losing files.
100
+
101
+ AWS_S3_FILE_OVERWRITE = False
102
+
103
+
104
+
105
+ # Default ACL for new files should be "private" - not accessible to the
106
+
107
+ # public. Images should be made available to public via the bucket policy,
108
+
109
+ # where the documents should use wagtail-storages.
110
+
111
+ AWS_DEFAULT_ACL = "private"
112
+
113
+
114
+
115
+ # We generally use this setting in production to put the S3 bucket
116
+
117
+ # behind a CDN using a custom domain, e.g. media.llamasavers.com.
118
+
119
+ # https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#cloudfront
120
+
121
+ if "AWS_S3_CUSTOM_DOMAIN" in os.environ:
122
+
123
+ AWS_S3_CUSTOM_DOMAIN = os.environ["AWS_S3_CUSTOM_DOMAIN"]
124
+
125
+
126
+
127
+ # When signing URLs is enabled, the region must be set.
128
+
129
+ # The global S3 endpoint does not seem to support signed URLS.
130
+
131
+ # Set this only if you will be using signed URLs.
132
+
133
+ if "AWS_S3_REGION_NAME" in os.environ:
134
+
135
+ AWS_S3_REGION_NAME = os.environ["AWS_S3_REGION_NAME"]
136
+
137
+
138
+
139
+ # This settings lets you force using http or https protocol when generating
140
+
141
+ # the URLs to the files. Set https as default.
142
+
37
- [GitHubの該当ソースのページ](https://github.com/huideyeren/huidetang/blob/main/backend/huidetang/settings/localhost.py)
143
+ # https://github.com/jschneier/django-storages/blob/10d1929de5e0318dbd63d715db4bebc9a42257b5/storages/backends/s3boto3.py#L217
144
+
145
+ AWS_S3_URL_PROTOCOL = os.environ.get("AWS_S3_URL_PROTOCOL", "https:")
146
+
147
+
148
+
149
+ AWS_S3_ENDPOINT_URL = os.environ["AWS_S3_ENDPOINT_URL"]
150
+
151
+
152
+
153
+ AWS_LOCATION = "wagtail"
154
+
155
+
156
+
157
+ AWS_S3_USE_SSL = False
158
+
159
+ AWS_S3_SECURE_URLS = False
160
+
161
+
162
+
163
+ STATICFILES_STORAGE = "storages.backends.s3boto3.S3StaticStorage"
164
+
165
+ STATIC_URL = "http://localhost:9090/minio/wagtail/%s/" % (AWS_LOCATION)
166
+
167
+ ```
168
+
169
+
170
+
171
+ #### docker-compose.yml
172
+
173
+
174
+
175
+ ```yaml
176
+
177
+ version: '3.7'
178
+
179
+ services:
180
+
181
+ nginx:
182
+
183
+ image: nginx:latest
184
+
185
+ volumes:
186
+
187
+ - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
188
+
189
+ ports:
190
+
191
+ - 80:80
192
+
193
+ depends_on:
194
+
195
+ - backend
196
+
197
+ - frontend
198
+
199
+ postgres:
200
+
201
+ image: postgres:12
202
+
203
+ restart: always
204
+
205
+ environment:
206
+
207
+ POSTGRES_USER: postgres
208
+
209
+ POSTGRES_PASSWORD: password
210
+
211
+ ports:
212
+
213
+ - '5432:5432'
214
+
215
+ volumes:
216
+
217
+ - db-data:/var/lib/postgresql/data:cached
218
+
219
+ backend:
220
+
221
+ build:
222
+
223
+ context: backend
224
+
225
+ dockerfile: Dockerfile
226
+
227
+ volumes:
228
+
229
+ - ./backend:/app/:cached
230
+
231
+ environment:
232
+
233
+ PYTHONPATH: .
234
+
235
+ DATABASE_URL: 'postgresql://postgres:password@postgres:5432/postgres'
236
+
237
+ AWS_S3_CUSTOM_DOMAIN: 'localhost:9090/minio/wagtail'
238
+
239
+ AWS_S3_ENDPOINT_URL: 'http://minio:9000/'
240
+
241
+ AWS_STORAGE_BUCKET_NAME: 'wagtail'
242
+
243
+ AWS_ACCESS_KEY_ID: 'huidetang'
244
+
245
+ AWS_S3_REGION_NAME: 'us-east-1'
246
+
247
+ AWS_SECRET_ACCESS_KEY: 'jsYIDsqqIt9JShu'
248
+
249
+ AWS_S3_URL_PROTOCOL: 'http:'
250
+
251
+ depends_on:
252
+
253
+ - "postgres"
254
+
255
+ - "minio"
256
+
257
+ frontend:
258
+
259
+ build:
260
+
261
+ context: frontend
262
+
263
+ dockerfile: Dockerfile
264
+
265
+ stdin_open: true
266
+
267
+ volumes:
268
+
269
+ - './frontend:/app:cached'
270
+
271
+ - './frontend/node_modules:/app/node_modules:cached'
272
+
273
+ environment:
274
+
275
+ - NODE_ENV=development
276
+
277
+ minio:
278
+
279
+ image: minio/minio:latest
280
+
281
+ ports:
282
+
283
+ - 9090:9000
284
+
285
+ volumes:
286
+
287
+ - ./minio/data:/data
288
+
289
+ - ./minio/export:/export
290
+
291
+ - ./minio/config:/root/.minio
292
+
293
+ - ./minio/policies:/policies
294
+
295
+ environment:
296
+
297
+ MINIO_ACCESS_KEY: 'huidetang'
298
+
299
+ MINIO_SECRET_KEY: 'jsYIDsqqIt9JShu'
300
+
301
+ entrypoint:
302
+
303
+ - /bin/sh
304
+
305
+ - -c
306
+
307
+ command:
308
+
309
+ - "mkdir -p /data/.minio.sys/buckets; cp -r /policies/* /data/.minio.sys/; cp -r /export/* /data/; /usr/bin/minio server /data"
310
+
311
+ createbuckets:
312
+
313
+ image: minio/mc
314
+
315
+ depends_on:
316
+
317
+ - minio
318
+
319
+ entrypoint: >
320
+
321
+ /bin/sh -c "
322
+
323
+ until (/usr/bin/mc config host add wagtail http://minio:9000 huidetang jsYIDsqqIt9JShu) do echo '...waiting...' && sleep 1; done;
324
+
325
+ /usr/bin/mc mb wagtail/wagtail;
326
+
327
+ /usr/bin/mc admin user add wagtail wagtail jsYIDsqqIt9JShu;
328
+
329
+ exit 0;
330
+
331
+ "
332
+
333
+ volumes:
334
+
335
+ db-data:
336
+
337
+
338
+
339
+ ```
340
+
341
+
342
+
343
+ #### policy.json(MinIO)
344
+
345
+
346
+
347
+ ```json
348
+
349
+ {
350
+
351
+ "Version": "2012-10-17",
352
+
353
+ "Statement": [
354
+
355
+ {
356
+
357
+ "Sid": "AllowUserManageBucket",
358
+
359
+ "Effect": "Allow",
360
+
361
+ "Principal": "*",
362
+
363
+ "Action": [
364
+
365
+ "s3:ListBucket",
366
+
367
+ "s3:GetBucketLocation",
368
+
369
+ "s3:ListBucketMultipartUploads",
370
+
371
+ "s3:ListBucketVersions"
372
+
373
+ ],
374
+
375
+ "Resource": "arn:aws:s3:::wagtail"
376
+
377
+ },
378
+
379
+ {
380
+
381
+ "Sid": "AllowUserManageBucketObjects",
382
+
383
+ "Effect": "Allow",
384
+
385
+ "Principal": "*",
386
+
387
+ "Action": [
388
+
389
+ "s3:GetObject",
390
+
391
+ "s3:PutObject",
392
+
393
+ "s3:DeleteObject"
394
+
395
+ ],
396
+
397
+ "Resource": "arn:aws:s3:::wagtail/*"
398
+
399
+ }
400
+
401
+ ]
402
+
403
+ }
404
+
405
+
406
+
407
+ ```
408
+
409
+
38
410
 
39
411
 
40
412
 
@@ -42,13 +414,13 @@
42
414
 
43
415
 
44
416
 
45
- 静的ファイルの設定以下のようにして動くかどうか確かめていま
417
+ 静的ファイルの設定は最初以下のようにしていました
46
418
 
47
419
 
48
420
 
49
421
  ```python
50
422
 
51
- STATICFILES_STORAGE = 'storages.backends.s3boto3.S3StaticStorage'
423
+ STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
52
424
 
53
425
  ```
54
426