Score:0

NGINX try_files across multiple drives on Windows

us flag

I am moving nginx out of a Linux VM to the Windows host for performance reasons and I'm having trouble with this part.

On Linux the configuration is:

root /;

try_files /mnt/m$uri /mnt/d$uri /mnt/l$uri =404;

Where /mnt/m, /mnt/d and /mnt/l are the mount points of the M:, D: and L: drives respectively.

On Windows I tried

root /;

try_files M:$uri D:$uri L:$uri =404;

but it throws this error

*1 GetFileAttributesEx() "C:L:/[...]" failed (123: The filename, directory name, or volume label syntax is incorrect)

It seems / is interpreted as the C: drive, it's the drive that nginx runs from. I also tried root ; and leaving the root directive out altogether but nothing worked.

Ivan Shatsky avatar
gr flag
Not sure it is possible at all. If you really need that functionality, why not to use NTFS mount points for different hard drives?
erik avatar
us flag
@IvanShatsky It was actually possible just through the config, but it's a rather hacky solution. I had no idea NTFS had mount points, it would've saved me a lot of stress lmao
Score:0
us flag

I managed to do it by nesting(?) named locations. Though be careful as any headers/options you set in the main location block won't apply in the named locations, at least in my experience. @IvanShatsky's solution with NTFS mount points seems to be a lot better.

location /  {
    root "M:\\";
    try_files $uri $uri/ @ddrive;

}

location @ddrive {
    root "D:\\";
    try_files $uri $uri/ @ldrive;
}

location @ldrive {
    root "L:\\";
    try_files $uri $uri/ =404;
}
Ivan Shatsky avatar
gr flag
I don't think you really need an `$uri/` component of `try_files` directive. It is used only to check if an `$uri` is a directory containing any index file, and you didn't have it in your original config. A few words words about headers/options inheriting. When you have a number of location sharing common headers/options, you can move those definitions one level up, but you can't define an additional header inside the location without loosing all the header inheritance from the previous level. That is, define nothing and inherit everything or define everything.
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.