gpt4 book ai didi

html - Nginx 找到 css 但没有将其加载到 index.html

转载 作者:技术小花猫 更新时间:2023-10-29 11:56:38 26 4
gpt4 key购买 nike

我的 nginx 服务器提供一个 index.html 文件,它加载一个 css 文件和一些 js 文件。 css 文件已加载(NO 404),但样式未出现。

文件夹:

/src
/assets
/images
...
/sounds
...
/css
/style.css
/js
...
index.html

由 js 文件加载的声音和图像完美运行。

/etc/nginx/sites-enabled/default/:

server {
listen 8080;
server_name jumpnrun jumpnrun.vm;
access_log /var/log/nginx/jumpnrun.access.log;
error_log /var/log/nginx/jumpnrun.error.log;

location / {
try_files $uri $uri/index.html;
}

location ~ ^/(assets/|css/|js/|index.html) {
root /src;
index index.html;
access_log off;
}

location /socket.io {
add_header Access-Control-Allow-Origin *;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_pass http://node-server;
}

}

索引.html :

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Jump n' Run</title>
<link href="css/style.css" type="text/css" rel="stylesheet" />
</head>
<body>
<canvas id="game" width='1000' height='500'></canvas>
<button class="sound"></button>
</body>
<!-- JS -->
</html>

如果我转到 localhost:8080,它会给我索引页面,但没有任何样式,开发工具也不会显示任何错误。

感谢您的帮助!

编辑:

整个东西都在一个 docker 容器中.. 现在每次我浏览到 localhost:8080 nginx 都会死掉。错误日志不知何故无法访问..

最佳答案

我有一个类似的问题,并通过确保我的 nginx.conf 中的 http block 正在加载正确的 mime.types 映射来解决它:

http { 
include /etc/nginx/mime.types;
}

关于html - Nginx 找到 css 但没有将其加载到 index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29432097/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com