L
L
l4m3r2019-03-27 18:42:47
Nginx
l4m3r, 2019-03-27 18:42:47

How to change root in nginx?

There is a working site config.

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$ {
        fastcgi_pass 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 can I make /admin and all sorts of /admin/xxx/yyy/ggg work out the same rules, but with a different root?
Added:
location /admin {
        alias /var/www/html/backend/web;
    }

   location / { ... }

Does not work. 404 by /admin

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
ky0, 2019-03-27
@ky0

Add another root inside the location, it will take precedence over the global one.

D
Dmitry Derepko, 2019-03-27
@xEpozZ

location ~ ^/admin/?(.+) {
   set $root /backend/web;
   try_files $root/$1 /$uri $root/$uri $root/index.php$is_args$args;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question