html - 使用 NGINX,css 文件不工作

标签 html css nginx

css 文件正在加载,但问题是它们没有应用,但这是奇怪的部分。如果我以任何方式在 chrome 中编辑它(输入一个字符并删除它),样式表就会应用。我相当确定问题出在 nginx 上,因为当我运行本地服务器 (node.js http-server) 时,css 文件有效。

我将它添加到我的配置中以确保它正在发送并被解释为正确类型的文件,但它仍然不起作用。

location ~ \.css {
  add_header Content-Type text/css;
}

This is the website if anyone wants to look at it or try editing the css file.

最佳答案

如果您查看发送到浏览器的 header ,现在会收到两种内容类型,这是错误的。浏览器将 CSS 解释为纯文本,因此无法应用该 css。

Content-Type:text/plain
Content-Type:text/css

您的 nginx 配置是什么样的?你包括/etc/nginx/mime.types;任何地方都一样:https://www.nginx.com/resources/wiki/start/topics/examples/full/

关于html - 使用 NGINX,css 文件不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43362021/

相关文章:

javascript - 如何使用jquery只追加一次数据

html - 在计算机上看到的网站字体与之前上传到网络主机上的网站字体不同。如何纠正?

javascript - 在 Clarity DataGrid 中,如何更改整列的文本对齐属性?

javascript - 输入范围 slider 及其指针的自定义

html - Firefox 中的对象适合意外结果

macos - 如何绑定(bind)80非root

html - Bootstrap alertinfo 与标题中的按钮合并

php - 运行 PHP 时 Nginx 403 Forbidden

laravel - Laradock 404 找不到 nginx

jquery - 在隐藏的输入字段中键入内容