加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

nginx The requested URL /404.html was not found on this serv

发布时间:2020-12-13 17:53:57 所属栏目:Linux 来源:网络整理
导读:使用django+nginx+gunicorn部署网站时,发现静态文件请求时,均报错 The?requested?URL?/404.html?was?not?found?on?this?server chenxm.cc.conf server?{???#?这个server标识我要配置了????????listen?80;??#?80?是http默认的端口,?443?是https默认的端口

使用django+nginx+gunicorn部署网站时,发现静态文件请求时,均报错

The?requested?URL?/404.html?was?not?found?on?this?server

chenxm.cc.conf

server?{???#?这个server标识我要配置了
????????listen?80;??#?80?是http默认的端口,?443?是https默认的端口(网页一般使用这两个端口)
????????server_name?www.chenxm.cc?;??#?你访问的路径前面的url名称
????????access_log??/var/log/nginx/access.log;??#?Nginx日志配置
????????error_log??/var/log/nginx/error.log;????#?Nginx错误日志配置
????????charset??utf-8;?#?Nginx编码
????????gzip?on;??#?启用压缩,这个的作用就是给用户一个网页,比如3M压缩后1M这样传输速度就会提高很多
????????gzip_types?text/plain?application/x-javascript?text/css?text/javascript?application/x-httpd-php?application/json?text/json?image/jpeg?image/gif?image/png?application/octet-stream;??#?支持压缩的类型

????????error_page??404???????????/404.html;??#?错误页面
????????error_page???500?502?503?504??/50x.html;??#?错误页面

????????location?/?{
?????????proxy_pass?http://0.0.0.0:8080;
?????????proxy_set_header?Host?$host;
?????????proxy_set_header?X-Real-IP?$remote_addr;
?????????proxy_set_header?X-Forwarded-For?$proxy_add_x_forwarded_for;
?????}


????????#?指定静态文件路径
????????location?/static/?{
????????????alias??/home/chenxinming/chenCms/static;
????????????index??index.html?index.htm;
????????}
????????}

打开nginx的error.log

sudo?tail?-n?20?/var/log/nginx/error.log

日志如下:

2019/07/22?23:09:52?[error]?8441#8441:?*11?open()?"/home/chenxinming/chenCms/staticdefault/script/superfish.js"?failed?(2:?No?such?file?or?directory),?client:?221.217.182.122,?server:?a.chenxm.cc,?request:?"GET?/static/default/script/superfish.js?HTTP/1.1",?host:?"a.chenxm.cc",?referrer:?"http://a.chenxm.cc/"
2019/07/22?23:09:52?[error]?8441#8441:?*1?open()?"/home/chenxinming/chenCms/staticdefault/fonts/fontawesome-all.css"?failed?(2:?No?such?file?or?directory),?request:?"GET?/static/default/fonts/fontawesome-all.css?HTTP/1.1",?referrer:?"http://a.chenxm.cc/"
2019/07/22?23:09:52?[error]?8441#8441:?*1?open()?"/home/chenxinming/chenCms/staticdefault/script/superfish.js"?failed?(2:?No?such?file?or?directory),?referrer:?"http://a.chenxm.cc/"
2019/07/22?23:22:42?[error]?8441#8441:?*114?open()?"/home/chenxinming/chenCms/staticdefault/plugin/layuiadmin/layui/css/layui.css"?failed?(2:?No?such?file?or?directory),?request:?"GET?/static/default/plugin/layuiadmin/layui/css/layui.css?HTTP/1.1",?host:?"a.chenxm.cc"

检查了下静态文件实际路径和error.log中发现缺少了一个目录。经过排查原来是chenxm.cc中静态了路径少写了一个斜杠

如:

location?/static/?{
		alias??/home/chenxinming/chenCms/static/;
		index??index.html?index.htm;
????????}


(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读