Nginx Django App不提供SVG文件

时间:2015-09-18 13:22:39

标签: python django svg nginx

所以我在端口8000上有一个RatticDB安装设置(Django App),前面我在端口80上有Nginx。它当前正在服务svg文件作为application / octet-stream导致svg文件被下载vs服务。

rattic.conf:

upstream django {
    server      127.0.0.1:8000;
}

server {
    listen          80;
    server_name         locksmith.internal.domain.com;
    charset         utf-8;
    client_max_body_size    75M;

    location /raddicweb/static {
    alias       /home/locksmith/RatticWeb/ratticweb/static;
    }

    location /cred/static {
    alias       /home/locksmith/RatticWeb/cred/static;
    }

    location / {
    uwsgi_pass  django;
    include     /etc/nginx/uwsgi_params;
    }

    types {
    image/svg+xml   svg svgz;
    }

  }

现在nginx.conf包含mime类型,mime类型有这个设置,我从哪里开始? [root @ ip~] #grep -R mime.types / etc / nginx / /etc/nginx/nginx.conf:include /etc/nginx/mime.types; [root @ ip~]#grep svg /etc/nginx/mime.types     image / svg + xml svg svgz;

1 个答案:

答案 0 :(得分:0)

显然,Django需要服务这些以及nginx;所以问题是在Django级别,并通过将以下内容添加到settings.py并重新启动uwsgi来解决:

import mimetypes

mimetypes.add_type("image/svg+xml", ".svg", True)
mimetypes.add_type("image/svg+xml", ".svgz", True)