账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    nginx 反向代理配置后,首页404
    65
    0

    本地代理,开发线上接口。用了nginx反向代理。结果就是首页必须带index.html才能访问,直接访问斜杠/是404.

    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile      on;
        keepalive_timeout 10;
        upstream serverip {
            server xx.xx.xx.xx;
        }
    
        server {
            listen  80;
            server_name  a.com;
            
            location =/ {
                add_header X-Frame-Options SAMEORIGIN;
                index index.html;
            }
    
            location ~* \.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|swf|woff|woff2|ttf|json|svg|cur|vue|otf|eot)$ {
                charset     utf-8;
                root        D:/WWW/app;
                expires     3d;
            }
            
            location / {
                proxy_pass   http://serverip;
            }
        }
    }

    hosts:

    127.0.0.1 a.com

    如果我吧配置改成下面的,两种方式都能访问了:http://a.com/和http://a.com/index.html

    location =/ {
        add_header X-Frame-Options SAMEORIGIN;
        root        D:/WWW/app;
        index index.html;
    }
    
    location ~* \.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|swf|woff|woff2|ttf|json|svg|cur|vue|otf|eot)$ {
        charset     utf-8;
        root        D:/WWW/app;
        expires     3d;
    }

    看了一下日志
    D:WWWappnginx/html/index.html" is not found (3: The system cannot find the path specified),

    这里说明一下,我的项目目录:
    www/app/index.html
    www/app/nginx/*

    我想问,一定要配置两个root么?能配置两个root么?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 秋末♂残雪℡ 普通会员 1楼

      404错误通常表示目标资源未找到,这可能是由于以下原因:

      1. 目标URL错误:请检查您的URL是否正确,特别是URL中的路径部分是否正确。

      2. 代理配置问题:请确认您的Nginx代理配置是否正确。例如,您是否正确设置了proxy_pass和proxy_cache的路径和内容?

      3. 目标资源路径错误:请检查目标资源的路径是否正确,特别是目标资源路径中的文件或目录名是否正确。

      4. 网络问题:请检查您的网络连接是否正常,尤其是服务器和客户端之间的网络连接是否稳定。

      5. 路由问题:请检查您的服务器上的路由设置是否正确,尤其是URL是否正确地指向目标资源。

      如果您已经尝试了上述解决方案,但仍然无法解决问题,可能需要寻求专业的帮助,例如联系服务器管理员或使用专门的故障排除工具。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部