使用Nginx的虚拟路径

使用Nginx的虚拟路径,nginx,Nginx,我正在尝试使用nginx从虚拟路径提供文件。当我转到/test时,nginx通常会查找根/test/index.html,但我想查找根/index.html server { ... root /usr/share/nginx/html; index index.html; location / {} location /test/ { rewrite ^/test(.*)$ $1 last

我正在尝试使用nginx从虚拟路径提供文件。当我转到
/test
时,nginx通常会查找
根/test/index.html
,但我想查找
根/index.html

server {
    ...
    root         /usr/share/nginx/html;
    index        index.html;

    location / {}

    location /test/ {
        rewrite         ^/test(.*)$ $1 last;
        root            /var/www/html;
    }
    ...
}

这里的问题是,当导航到
/test
时,nginx从
/usr/share/nginx/html
提供索引文件,而不是像我解释的那样提供
/var/www/html

尝试将配置更改为类似的内容

server {
    ...
    index        index.html;

    location / {
       root         /usr/share/nginx/html;
    }

    location /test {
        rewrite         ^/test(.*)$ $1 last;
        root            /var/www/html;
    }
    ...
}