【问题标题】:Resource interpreted as Stylesheet but transferred with MIME type text/html: "<URL>"资源解释为样式表,但使用 MIME 类型 text/html 传输:“<URL>”
【发布时间】:2021-04-25 23:05:15
【问题描述】:

看起来像重复?不,不是!

这些是我的配置:

  1. 操作系统:Fedora 33 服务器
  2. PHP:PHP 7.4.13
  3. MySQL:MySQL 8.0

我会像这样在我的服务器上设置 WordPress:

  1. Nginx 面向互联网。
  2. Nginx 将请求传递给 PHP-fpm。
  3. PHP-fpm 然后处理之后的所有事情。

一切似乎都运行良好,但我不知道到底发生了什么?从字面上看,任何类型的主题都不起作用。我尝试了很多主题,但似乎都没有效果。

看一下页面:https://blog.harshrathod.dev

我收到了这个奇怪的警告,并且样式根本不生效:

Resource interpreted as Stylesheet but transferred with MIME type text/html: "<URL>".
(index):29 Resource interpreted as Stylesheet but transferred with MIME type text/html: "https://php.harshrathod.dev/wp-includes/css/dashicons.min.css?ver=5.6".
(index):30 Resource interpreted as Stylesheet but transferred with MIME type text/html: "https://php.harshrathod.dev/wp-includes/css/admin-bar.min.css?ver=5.6".
(index):31 Resource interpreted as Stylesheet but transferred with MIME type text/html: "https://php.harshrathod.dev/wp-includes/css/dist/block-library/style.min.css?ver=5.6".
(index):32 Resource interpreted as Stylesheet but transferred with MIME type text/html: "https://php.harshrathod.dev/wp-includes/css/dist/block-library/theme.min.css?ver=5.6".
(index):33 Resource interpreted as Stylesheet but transferred with MIME type text/html: "https://php.harshrathod.dev/wp-content/themes/twentynineteen/style.css?ver=1.8".
(index):34 Resource interpreted as Stylesheet but transferred with MIME type text/html: "https://php.harshrathod.dev/wp-content/themes/twentynineteen/print.css?ver=1.8".

这是我的 nginx 配置:

root        /usr/share/wordpress;

location / {
    try_files      $uri $uri/ =404;
    fastcgi_pass   127.0.0.1:4000;
    fastcgi_index  index.php;
    fastcgi_param  PATH_INFO        $fastcgi_path_info;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

【问题讨论】:

  • 它可能是重复的。当找不到文件时,您将请求发送到/index.php,它总是以test/html 响应(这很好,因为这就是漂亮的永久链接的工作方式)。问题是找不到这些文件 - 可能是因为它们丢失、读保护,或者 Nginx 没有正确配置来定位它们。
  • 好的,我已经提供了我的 nginx 配置。你能在这里找到什么奇怪的东西吗?
  • 该配置将请求发送到 PHP,PHP 以 text/html 的形式响应“拒绝访问”。您应该首先将location 更改为location ~ \.php$,以便将非PHP 文件视为静态文件。完整的配方是documented here
  • 好的,这解决了我的问题。谢谢!

标签: php wordpress nginx


【解决方案1】:

读完issue后,我发现实际问题出在我的nginx配置上。

由于我只有一个且唯一的路由,发生的情况是静态文件也被 php-fpm 解析,并将它们作为 html/txt 发送给客户端。

解决方案是我们需要有两条不同的路线:

  1. 一个为所有静态的。
  2. 第二个用于处理php文件。

因此,生成的 nginx 配置将如下所示:

root /usr/share/wordpress;

location / {
    index index.php;
}

location ~ \.php$ {
    try_files      $uri $uri/ =404;
    fastcgi_pass   127.0.0.1:4000;
    fastcgi_index  index.php;
    fastcgi_param  PATH_INFO        $fastcgi_path_info;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

【讨论】:

    猜你喜欢
    • 2012-05-20
    • 2014-11-19
    • 2013-05-04
    • 2011-12-13
    • 2017-10-12
    • 2016-03-19
    • 1970-01-01
    • 2017-02-23
    • 2018-01-23
    相关资源
    最近更新 更多