Score:0

nginx - subfolders alias include all subfolder

de flag

I'm currently trying to fiddle around with a location block that has a different root. However I have some issues when accessing files that are in a subfolder on the different root.

Here is my broken location block and below it I will explain the exact issue:

  location /maps                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
    {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
        alias /online/www/maps.domain.com;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
        try_files $uri $uri/ @nested;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
    }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
   location @nested {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
        rewrite /maps/(.*)$ ~/maps/$2;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
    }                                      

Here I try that /maps on my root domain (domain.com/maps) has a different root. That works for files directly on /online/www/maps.domain.com

However if I have a subfolder there e.g. /online/www/maps.domain.com/folder1 I can't speak to it via domain.com/maps/folder1 and so can't access files there.

Is there any "dynamic" way to achieve this? Or do I need to add another location block for that sub-sub-folder?

Thanks.

~ Alex

Score:0
de flag

After posting the question and getting some coffee I found the solution... And it was really that simple too,.

Here it is:

location /maps                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
    {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
        alias /online/www/maps.domain.com/$1;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
    }                    

Only thing I had to do was adding a variable at the end of the folder alias. Yikes...

us flag
This configuration looks incomplete, there is no value set to `$1` variable.
Aebian avatar
de flag
However it works for me nonetheless. My assumption is that $1 will be filled with a default value from the url when not explicitly specified.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.