为什么 nginx 将位置上下文路径作为根位置的前缀?

Pab*_*blo 5 nginx

我在 nginx 的“sites-available”文件夹中有一个简单的默认网站配置,如下所示。

当我尝试浏览到/hello 时,我希望它为位于我指定的根文件夹中的 index.html 文件提供服务。相反,它试图在我指定的根位置获取 /hello/index.html。

有没有办法告诉 nginx 在不为上下文路径添加前缀的情况下提供文件?

root /var/...;

location / {
    ...
}

location /hello/ {
    root /home/vagrant/public_html/project/dist;
}
Run Code Online (Sandbox Code Playgroud)

sen*_*nfo 2

使用alias而不是root; 引用http://nginx.org/en/docs/http/ngx_http_core_module.html#alias

\n\n
\n

例如,使用以下配置

\n
\n\n
location /i/ {\n    alias /data/w3/images/;\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n
\n

根据 \xe2\x80\x9c/i/top.gif\xe2\x80\x9d 的请求,将发送文件 /data/w3/images/top.gif。

\n
\n