【问题标题】:Nginx can't load CSS FilesNginx 无法加载 CSS 文件
【发布时间】:2016-02-09 08:52:45
【问题描述】:

不知何故,nginx 无法加载 CSS 文件并导致网站显示没有 CSS。

在 Firefox 中,我收到了这些警告:

样式表http://192.168.1.10:6000/templates/main/css/layout.css 未加载,因为它的 MIME 类型“text/html”不是“text/css”。

样式表http://192.168.1.10:6000/templates/main/css/jqevent.css 未加载,因为它的 MIME 类型“text/html”不是“text/css”。

样式表http://192.168.1.10:6000/templates/main/css/crud.css 未加载,因为它的 MIME 类型“text/html”不是“text/css”。

Nginx 配置

user  root;

http {

    include       /home/school/webapp/nginx/conf/mime.types;

    default_type  application/octet-stream;


    server {
        listen 6000;
        index index.php index.html index.htm;
        root /home/school/webapp/wwwdir/;

               location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

    }
}

【问题讨论】:

  • 此链接可能对您有所帮助:stackoverflow.com/questions/29573489/…
  • 不走运,我已经花了 3 天时间试图解决它并阅读...我也访问了该线程但尚未成功...
  • 但是您提供的 nginx 配置是否完整?因为如果是,我看不到任何特定于 css 的配置。
  • stackoverflow.com/questions/10075304/… ----- 这与你的情况类似......你也可以尝试改变你的默认类型......到 /etc/nginx/ mime.types 来自 application/octet-stream;
  • @Bogdan ,为什么我要特定的 css conf ? . sagarthapa ,我没有运气......

标签: php css nginx debian


【解决方案1】:

你应该在你的 nginx.conf 中包含 mime 类型。在此处查看默认的 nginx.conf:https://www.nginx.com/resources/wiki/start/topics/examples/full/

只需添加以下行包含在位置/

包括 conf/mime.types;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-16
    • 2012-04-21
    • 2019-01-16
    • 2016-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多