nginx未检测到CSS和JS-服务器响应状态为404

wlp8pajw  于 2023-01-04  发布在  Nginx
关注(0)|答案(1)|浏览(319)

这是我的nginx. conf. CSS和JS在这个文件夹里

/usr/share/nginx/static/css
/usr/share/nginx/static/js
/usr/share/nginx/static/media
location ~ (css|js|img) {
  root /usr/share/nginx/html;
  try_files $uri $uri/ =404;
}

location / {

  root /usr/share/nginx/html;
}

但我收到了这个错误

Failed to load resource: the server responded with a status of 404 (Not Found)                               2.0fe3a37f.chunk.css:1 
Failed to load resource: the server responded with a status of 404 (Not Found)                               2.0a7ada56.chunk.js:1 
Failed to load resource: the server responded with a status of 404 (Not Found)                               main.e5e7c1e6.chunk.css:1 
Failed to load resource: the server responded with a status of 404 (Not Found)                               main.8a3eed81.chunk.js:1 
Failed to load resource: the server responded with a status of 404 (Not Found)                               2.0a7ada56.chunk.js:1 
Failed to load resource: the server responded with a status of 404 (Not Found)                               main.8a3eed81.chunk.js:1 
Failed to load resource: the server responded with a status of 404 (Not Found)                               2.0fe3a37f.chunk.css:1 
Failed to load resource: the server responded with a status of 404 (Not Found)                               main.e5e7c1e6.chunk.css:1 
Failed to load resource: the server responded with a status of 404 (Not Found)                               main.e5e7c1e6.chunk.css:1
0ejtzxu1

0ejtzxu11#

我有同样的问题,只有以下帮助我(我使用FastApi项目,并部署在AWS EC2服务器):
根路径取自以下信息(只需复制此命令到您的终端):

nginx -V 2>&1 | grep --color -o -e '--prefix=[^[:space:]]\+'

添加根路径,这是从上面的信息,到nginx.conf:

location /      {
                            proxy_pass http://127.0.0.1:8000;
                            root /usr/share/nginx;
            }

在css:

<link href="/static/css/index.css" rel="stylesheet">

相关问题