my nginx server serves an index.html file, which loads a css file and some js files. the css file is loaded (NO 404), but the style doesn't appear.
folders :
/src
/assets
/images
...
/sounds
...
/css
/style.css
/js
...
index.html
sound and images loaded by the js files work perfectly.
/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;
}
}
index.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>
if i go to localhost:8080 it gives me the index page but without any styling and the dev tools doesn't show me any errors.
thanks for your help!
EDIT:
The whole thing is in a docker container.. Now every time i browse to localhost:8080 nginx dies. error log is somehow not accessible..
Save this question.
The try_files directive exists for an amazing reason: It tries files in a specific order. NGINX can first try to serve the static content, and if it can't, it moves on. This means PHP doesn't get involved at all.
The index directive defines the index file's name (the default value is index.html ). To continue with the example, if the request URI is /images/some/path/ , NGINX delivers the file /www/data/images/some/path/index.html if it exists. If it does not, NGINX returns HTTP code 404 (Not Found) by default.
I had a similar problem and resolved it by making sure the http
block in my nginx.conf was loading the proper mime.types
mappings:
http {
include /etc/nginx/mime.types;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With