nginx的location匹配规则
老师好,下面的nginx配置,我用http://ip:89访问时,报404,从error.log日志看,没有匹配到“/”这个location,匹配到/imooc的location了,日志如下:
2021/03/15 00:42:26 [error] 2007#0: *78 open() "/home/imooc.html" failed (2: No such file or directory), client: 192.168.198.1, server: localhost, request: "GET / HTTP/1.1", host: "192.168.198.100:89"
但是我用alias进行配置,将“/”改为“/index”就可以正常匹配
server {
listen 89;
server_name localhost;
#允许跨域请求的域,*代表所有
add_header 'Access-Control-Allow-Origin' *;
#允许带上cookie请求
add_header 'Access-Control-Allow-Credentials' 'true';
#允许请求的方法,比如 GET/POST/PUT/DELETE
add_header 'Access-Control-Allow-Methods' *;
#允许请求的header
add_header 'Access-Control-Allow-Headers' *;
#对源站点验证
valid_referers *.imooc.com;
#非法引入会进入下方判断
#if ($invalid_referer) {
# return 404;
#}
location / {
root /usr/local/nginx/html;
#alias html;
index imooc.html;
}
location /imooc {
root /home;
}
location = /favicon.ico { #精确定位ifavicon.ico文件
log_not_found off; #找不到文件时日志不记录
access_log off; #关闭日志记录
}
}
正在回答 回答被采纳积分+1
相似问题
登录后可查看更多问答,登录/注册
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星