0

I have chroot environment with Apache and some website.

Outside of the chroot I have nginx that forwards the requests to the Apache.

However, there are some directories that I want nginx to serve faster so I did:

location ^~ /uploads/ {
    alias   /VM.01/sites/domain.com/uploads/;

    expires 90d;
}

That works OK, but inside /uploads folder there are a symlink made relative to chroot, something like /sites/images.

When nginx request this file, the symlink no longer works.

Unfortunately we can not change the symlink, because is done by third party software.

There are two workarounds I can think of, but I don't like the both.

  1. install nginx in chroot. then "outside" nginx forwards to "chroot" nginx, then if need request is forwarded to "chroot" Apache.
    this is way too complex and data go via 3 "layers". (I know I can do 2 layers)

  2. create a symlink '/sites/' outside of chroot.
    this breaks encapsulation, also what if there are second chroot that need same directory.

Currently I am using option 2

1 Answer 1

1

Why don't you add another location block for this symlink, e.g.

location ^~ /uploads/ {
    alias   /VM.01/sites/domain.com/uploads/;
    expires 90d;
}
location ^~ /uploads/symlink/ {
    alias   /VM.01/sites/images/;
    expires 90d;
}

Or you can use nested locations to inherit outer location parameters:

location ^~ /uploads/ {
    alias   /VM.01/sites/domain.com/uploads/;
    expires 90d;
    location ^~ /uploads/symlink/ {
        alias   /VM.01/sites/images/;
    }
}

Additionally, when location matches the last part of the alias directive value, nginx documentation recommends to use the root directive instead:

location ^~ /uploads/ {
    root   /VM.01/sites/domain.com;
    expires 90d;
    location ^~ /uploads/symlink/ {
        alias   /VM.01/sites/images/;
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .