我正在学习 nginx 配置,但发现了一个我无法解决的问题。我的 nginx.conf 文件中有这样的服务器上下文。
server {
listen 192.168.1.20:80;
server_name www.a.com;
root /usr/share/nginx/html/a/;
location = /extra {
index default.html;
}
location = /prova {
index index.html;
}
}
我的本地 DNS 主机文件是
127.0.0.1 localhost
192.168.1.19 www.linuxhelp2.com
127.0.0.1 tech.com
192.168.1.20 www.a.com
192.168.1.19 www.b.com
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
现在我期望当我输入www.a.com时,我会收到一个 404 错误,而如果我输入www.a.com/prova或www.a.com/extra我会得到index 指令 html 页面。但是当我输入www.a.com时,我得到了 index.html 页面,而www.a.com/extra和www.a.com/prova都得到了 404 错误。index.html 和 default.html 都在 /usr/share/nginx/html/a/ 文件夹中。我究竟做错了什么?