Nginx rule to stream files behind the home directory?


Well-known member
Hey guys. Sometimes I need to download my backup files locally for testing purposes or just to keep them safe. The only way I could do ATM is to move them manually to the public directory which is really dangerous as it might get downloaded by others and/or I accidentally forget to remove them.

So any idea how to set nginx rule like rewrite or something that will allow me to stream files from the backups directory?

Thanks in advance.


Well-known member
Yes that did the trick, I have used alias before but I guess I was lazy to try lol

Here my rule for future reference:

location ~ ^/path/to/my/stream/([^/]+)$ {
    alias /my/backups/directory/$1.tar.gz;
Then you can use it like this:

The server will try to find this file: /my/backups/directory/anything.tar.gz;

Thank you @RoldanLT
Reactions: rdn