nginx The requested URL /404.html was not found on this server解决方法

前端之家收集整理的这篇文章主要介绍了nginx The requested URL /404.html was not found on this server解决方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

使用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;
        }


猜你在找的Linux相关文章