How to change the root in nginx?

There is a working config of the website.
server {
 listen 80;
 root /var/www/html/frontend/web;
 index index.php;
 charset utf-8;
 client_max_body_size 8M;

 error_log /dev/stderr;
 access_log /dev/stdout

 location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|xml|html|htm)$ {
 access_log off;
 add_header Cache-Control no-cache;
 expires 1s;

 location / {
 try_files $uri /index.php$is_args$args;

 location ~ \.php$ {
 location app:9000;
 fastcgi_index index.php;
 fastcgi_split_path_info ^(.+\.php)(/.*)$;
 include fastcgi_params;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 fastcgi_param PATH_INFO $fastcgi_path_info;

How do I do that when /any admin and /admin/xxx/yyy/ggg practiced the same rules, but with a different root?
location /admin {
 alias /var/www/html/backend/web;

 location / { ... }

Not working. 404 on /admin
March 19th 20 at 08:53
2 answers
March 19th 20 at 08:55
Add another Ruth inside the location, it will have higher priority over the global.
March 19th 20 at 08:57
location ~ ^/admin/?(.+) {
 set $root /backend/web;
 try_files $root/$1 /$uri $root/$uri $root/index.php$is_args$args;

Find more questions by tags Nginx