php - 资源解释为样式表,但使用 MIME 类型 text/html 传输:""
问题描述
好像是重复的?不它不是!
这些是我的配置:
- 操作系统:Fedora 33 服务器
- PHP:PHP 7.4.13
- MySQL:MySQL 8.0
我会在我的服务器上设置 WordPress,如下所示:
- Nginx 面向互联网。
- Nginx 将请求传递给 PHP-fpm。
- 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;
}
解决方案
阅读此问题后,我发现实际问题出在我的 nginx 配置上。
因为我只有一个也是唯一的路由,所以发生的事情是静态文件也被 php-fpm 解析,并将它们作为html/txt
.
对此的解决方案是我们需要有两条不同的路线:
- 一个为一切静态。
- 第二个用于处理 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;
}
推荐阅读
- xslt - 当用背景颜色填充的单元格是使用 xslt 的部分时,图像背景不可见
- apache-kafka - Kafka:使用选项自动创建主题
- c++ - C++ 编译器如何如此快速地评估递归 constexpr 函数?
- python - pip install terraform_utils 失败
- laravel-7 - 发现意外数据。尾随数据 Laravel 7
- random - 我怎么能随机移动这个三角形?p5.js
- css - 在 CSS 中,如何创建一个类以将填充放在带下划线的标题下方?
- java - 无法在 RestTemplate 中提取响应
- javascript - 将 Setter 函数传递给子组件时的单元测试 UseState
- windows - 在循环批处理文件中使用 CSV 变量