首页 > 解决方案 > Nginx 无法加载 text/css(在 docker 下运行)

问题描述

我有一个在 docker 后面运行的 Nginx。

这是我的 .conf 文件

events {
  worker_connections  2048;
}

http {
    default_type application/octet-stream;

    server {
        listen 80;
        index index.php index.html;
        root /var/www/public;

        location / {
            try_files $uri /index.php?$args;
        }

        location ~ \.css {
            include  /etc/nginx/mime.types;
            add_header Content-Type text/css;
        }

        location ~ \.js {
            add_header Content-Type application/x-javascript;
        }

        location ~ ^/(assets/|css/|js/|index.html) {
            root /var/www/public;
            index index.html;
            access_log off;
        }

        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass app:9000;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        }
    }
}

我在这里遵循了解决方案: Nginx 无法加载 css 文件

我也尝试过以下方法:

  1. 把包括/etc/nginx/mime.types; 在 http {

我检查了 mime.types 它具有正确的值,如下所示:

text/css                                         css;

我从 Chrome 开发控制台得到的结果是这样的:

Accept-Ranges: bytes
Content-Length: 52806
Content-Type: text/plain
Content-Type: text/css
Date: Thu, 20 Sep 2018 09:49:35 GMT
ETag: "5ba0bfef-ce46"

出于某种原因,Nginx 将其完全加载为 text/plain 和 text/css。

这是我正在使用的 Nginx 版本:

Server: nginx/1.15.3

编辑

有趣的是,如果我像这样 curl -v ,它将被视为文本/css

卷曲结果

谁能指出我正确的方向?谢谢

标签: dockernginx

解决方案


推荐阅读