nginx配置中的位置指令混乱



我希望在nginx配置中有一个url"localhost/test/"的位置指令。

我在配置文件中尝试了以下操作:

server {
listen 80;
server_name localhost;
location /test/ {
root /home/test;
index index.html index.htm
}

}

这总是给我一个404错误。然后我试了这个

server {
listen 80;
server_name localhost;
location / {
root /home/test;
index index.html index.htm
}

}

它在url"localhost"上运行良好

我不明白为什么在第一种情况下它会抛出404错误!!

配置的一个明显问题是必须使用别名而不是根

location /test/ {
    alias /home/test/;
}

因为,root让nginx根据您的配置搜索/home/test/test。

最新更新