鍍金池/ 問(wèn)答/Linux/ nginx 反向代理配置后,首頁(yè)404

nginx 反向代理配置后,首頁(yè)404

本地代理,開(kāi)發(fā)線上接口。用了nginx反向代理。結(jié)果就是首頁(yè)必須帶index.html才能訪問(wèn),直接訪問(wèn)斜杠/是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

如果我吧配置改成下面的,兩種方式都能訪問(wèn)了: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),

這里說(shuō)明一下,我的項(xiàng)目目錄:
www/app/index.html
www/app/nginx/*

我想問(wèn),一定要配置兩個(gè)root么?能配置兩個(gè)root么?

回答
編輯回答
夏夕

一定要配置root,不然根本找不到文件

2017年5月15日 09:49