外部css在localhost上工作正常,但在远程服务器上不工作

问题描述 投票:0回答:1

我在docker / nginx上部署了一个简单的网页index.html和一个简单的样式表。

index.html

<!DOCTYPE html>
<html lang="en">

<head>
  <link rel="stylesheet" type="text/css" href="css/mystyle.css">     
  <title>FlexBox</title>
</head>

<body>
<nav class="container">
  <div>Home</div>
  <div>Search</div>
  <div>Logout</div>
</nav>

</body>

</html> 

mystyle.css

body {
    background-color: red;
}

当我从服务器加载index.html时,我可以看到(f12)css文件已从服务器中拉出,但未应用。如果我对css文件进行了更改(例如通过f12 / developer工具添加空格),则将应用样式表。

ps:当我在本地通过vscode从liveserver查看网页时,它工作正常。没问题。

html css docker google-chrome nginx
1个回答
0
投票

已解决。问题在于Nginx conf为css指定mime类型

location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
        include /etc/nginx/mime.types;
} 
© www.soinside.com 2019 - 2024. All rights reserved.