V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
v2et
V2EX  ›  NGINX

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

  •  
  •   v2et · 2019-03-24 17:04:37 +08:00 · 4358 次点击
    这是一个创建于 1831 天前的主题,其中的信息可能已经有所发展或是发生改变。

    昨天配置 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;
    
        }
    }
    
    ebingtel
        1
    ebingtel  
       2019-03-24 19:05:52 +08:00
    proxy_pass http://localhost:8000/; 把末尾的 /去掉试试?
    v2et
        2
    v2et  
    OP
       2019-03-24 22:01:27 +08:00
    @ebingtel 试了,不行。但是一去掉<!DOCTYPE html>就可以了
    paloalto
        3
    paloalto  
       2019-03-25 09:12:45 +08:00 via iPhone
    ngnix 里配置 MIME TYPES
    paloalto
        4
    paloalto  
       2019-03-25 09:14:25 +08:00 via iPhone
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3716 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 10:40 · PVG 18:40 · LAX 03:40 · JFK 06:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.