1

I know there is a suggested solution in How to use try_files with 2 or more roots but it does not quite fit what I try to achieve.

We are in the process of migrating a big old webserver with 100,000s of pages to a new webserver. During this process we update the content. The directory for the new content was created from scratch. While we are updating the content we want to make sure that if something is missing in the new folder it can be retrieved from the old one.

My simplified folder structure looks like this:

/mnt/oldcontent
/var/opt/data/company/newcontent

For our scenario the ideal solution would be if we could do something like this:

location / {
  try_files /var/opt/data/company/newcontent/$uri /mnt/oldcontent/$uri ...;
}

I know this is invalid syntax.

1
  • I wonder if this could be solved with a server level root that I override with a newly defined location level root which I specify in try_files with something llike @oldcontentroot Commented Oct 4, 2018 at 16:30

1 Answer 1

2

Your solution would need the root to be set to the root of the filesystem.

As a location can only serve a single root, you could use a named location to try the other one.

For example:

root /var/opt/data/company/newcontent;

location / {
    try_files $uri $uri/ @oldcontent;
}
location @oldcontent {
    root /mnt/oldcontent;
    try_files $uri =404;
}

See this document for details.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, this works. And you showed me that my idea (see comment above) was not that wrong ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.