小编Jon*_*ner的帖子

Nginx找到css但不将其加载到index.html中

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

文件夹:

/src
    /assets
        /images
            ...
        /sounds
            ...
    /css
        /style.css
    /js
        ...
    index.html
Run Code Online (Sandbox Code Playgroud)

由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;
  }

}
Run Code Online (Sandbox Code Playgroud)

index.html:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" /> …
Run Code Online (Sandbox Code Playgroud)

html css nginx stylesheet

4
推荐指数
1
解决办法
3729
查看次数

标签 统计

css ×1

html ×1

nginx ×1

stylesheet ×1