本地代理,开发线上接口。用了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么?
一定要配置root,不然根本找不到文件