配置 Nginx 后 css 文件类型出错, MIME type 问题

2019-03-24 17:04:37 +08:00
 v2et

昨天配置 Nginx+gunicorn+flask 环境,配置 nginx 之前测试是可以正常显示的,一加了 nginx 之后 chrome 就显示Resource interpreted as Stylesheet but transferred with MIME type text/plain,之后试过在 nginx.conf 中加入include mime.types;add_header content-type text/css;都没用,后面只能把!DOCTYPE html去掉勉强解决。但是还是想不明白,到底是哪里导致 CSS 的类型出错的?请各位指教

引用 CSS 的语句类似这样:

<link href="/static/easyui/themes/metro/easyui.css" rel="stylesheet" type="text/css">

nginx 配置文件如下(因为非 root 用户运行,所以由 iptables 再转成 80 端口):

include /usr/local/nginx/conf/mime.types;
default_type application/octet-stream;
server 
{
    listen 8080;

    server_name localhost;

    access_log  /home/ubuntu/nginx/access.log;
    error_log  /home/ubuntu/nginx/error.log;

    location / 
    {
        proxy_pass         http://localhost:8000/;
        proxy_redirect     off;

        proxy_set_header   Host             $http_host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

    }
}
4393 次点击
所在节点    NGINX
4 条回复
ebingtel
2019-03-24 19:05:52 +08:00
proxy_pass http://localhost:8000/; 把末尾的 /去掉试试?
v2et
2019-03-24 22:01:27 +08:00
@ebingtel 试了,不行。但是一去掉<!DOCTYPE html>就可以了
paloalto
2019-03-25 09:12:45 +08:00
ngnix 里配置 MIME TYPES
paloalto
2019-03-25 09:14:25 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/548016

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX