0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

nginx + djangoで adminページのsvgが表示されないやつを直す

Posted at

初心者です

nginxとかに関しては全くの初心者で、そんな中引っかかった問題を書く。

環境

Docker: 2.0.0.3
django: 2.1.7
nginx: 1.15.9

問題

  • なんとかDockerでdjango + nginx + postgreの環境を整えて、デフォルトページが表示できた。
  • cssとかは動いているのにsvgだけ読み込まんのはなんで????

わかったこと

  • nginx側で静的ファイルをいい感じに振り分けていた。(djangoで/static/...のURIだったときはnginxの方にリクエストを流す)
  • どうやらmime.typesというファイルに、レスポンスするファイルのMIMEをすべて書き連ねないといかんらしい。
  • そうしないとnginx.confで設定されている application/octet-stream でヘッダが組まれてしまいいい感じにやってくれない

↓どっからかコピペしたnginx.conf

nginx.conf
...略
http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    access_log /tmp/nginx.access.log combined;
    sendfile on;
    ...全略
}

どうやらmime.typesに書かれていないMIMEが要求された時、ここのdefault_typeとやらに勝手になってしまって、正常にMIMEを認識してくれない -> svgとして読み取らんからレスポンスが無い。

というわけでまたまたどっかからコピペしたmime.typesにsvgのMIMEを調べて追加

mime.types
types {
    text/html                             html htm shtml;
    text/css                              css;
    text/xml                              xml rss;
    image/gif                             gif;
    image/jpeg                            jpeg jpg;
    image/svg+xml                         svg;    # <-ココ
    application/x-javascript              js;
    text/plain                            txt;
}

無事にsvgが表示されるようになったとさ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?