search

Home  >  Q&A  >  body text

yii2 - The difference between root in location and root in server in nginx

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

Access address www.xxx.com/site/test
The destination address I hope to access is www.xxx.com/web/index.php?r=site/test
But actually accessed It is www.xxx.com/index.php?r=site/test
That is, the root I set in the location does not work. If I set root /home/www/zscx/web at the beginning That’s good.
Explain why?

Change try_files $uri /index.php?$args;
to try_files $uri /web/index.php?$args;This is indeed possible, But the directory /web will still appear. What I want to achieve is www.domain.com/controller/function

In fact, it is to solve the pathinfo mode of Yii2

PHP中文网PHP中文网2807 days ago694

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-05-16 17:21:37

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

    reply
    0
  • 阿神

    阿神2017-05-16 17:21:37

    yii2 If you want to hide the web, just include the root path into the web. I remember in the yii documentation that only the web directory is accessible. As for the situation you mentioned, root is working, so there is no need to write the web path

    reply
    0
  • Cancelreply