",php,wordpress,nginx"/>

首页 > 解决方案 > 资源解释为样式表,但使用 MIME 类型 text/html 传输:""

问题描述

好像是重复的?不它不是!

这些是我的配置:

  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;
}

标签: phpwordpressnginx

解决方案


阅读此问题后,我发现实际问题出在我的 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;
}

推荐阅读