简体   繁体   中英

NGINX, How to use same location path for different target folder?

i am trying to use same location path in nginx.

location = / {
        root /usr/share/nginx/html/main;
        try_files $uri /index.html;
    }

        location  /  {
        root /usr/share/nginx/html/app;
            try_files $uri /index.html;
        }

but it is rendering app folder.

i am trying to achieve rendering 'main' folder html file in case of '/' path and 'app' folder html file in case of any other path.

You can't use the same location, you need to use different location for different folder. Even if you see "try_files" which use multiples points, "location" is different.

However, you can use multiple location like media in "/media" and "/" for html content or other.

Example

location /media {
    root /usr/share/nginx/html/app;
    try_files $uri /index.html;
}

location  /  {
    root /usr/share/nginx/html/main;
    try_files $uri /index.html;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM