首页 > nginx中location里的root和server里的root区别

nginx中location里的root和server里的root区别

server
    {
        ...
        #我在server中定义了root
        root  /home/www/zscx;
        ....
        #location中也定义一个root
        location /
        {
           root /home/www/zscx/web;
           try_files $uri /index.php?$args;
        }
        ...
    }
    

访问地址www.xxx.com/site/test
希望访问到的目的地址是www.xxx.com/web/index.php?r=site/test
但是实际上访问到得是www.xxx.com/index.php?r=site/test
也就是我在location中设置的root没有起作用啊,如果在最开始设置root /home/www/zscx/web那就是好的。
求解为什么?

try_files $uri /index.php?$args;
改为try_files $uri /web/index.php?$args;这样子确实可以,但是还是会出现/web这个目录。我想实现的是www.domain.com/controller/function

其实就是为了解决Yii2的pathinfo模式


yii2你想把web隐藏掉,root路径包含到web就可以了,yii文档里我记得有说只有 web目录是可访问的。至于你说的那个情况是root有起作用啊,所以才不用写web路径


https://github.com/yiisoft/yii2/blob/master/docs%2Fguide%2Fstart-installation.md#recommended-nginx-configuration-

【热门文章】
【热门文章】