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
https://github.com/yiisoft/yii2/blob/master/docs%2Fguide%2Fstart-installation.md#recommended-nginx-configuration-
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