簡體   English   中英

NGINX, 如何對不同的目標文件夾使用相同的位置路徑?

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

我正在嘗試在 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;
        }

但它正在渲染應用程序文件夾。

我正在嘗試在“/”路徑的情況下呈現“主”文件夾 html 文件,在任何其他路徑的情況下呈現“app”文件夾 html 文件。

您不能使用相同的位置,您需要為不同的文件夾使用不同的位置。 即使您看到使用多個點的“try_files”,“位置”也是不同的。

但是,您可以使用多個位置,例如“/media”中的媒體和“/”中的 html 內容或其他內容。

例子

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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM