Search code examples
nginxstatic-files

How to serve file under root path using Nginx?


I have a website laike9m.com, which is served by Nginx. I want to access a text file AAA.txt with url laike9m.com/AAA.txt. The text file is on my server, let's say it's $HOME/AAA.txt. Redirection is not allowed. Current Nginx conf file is here. Thank you.


Solution

  • location ~ ^(.*\.txt)$ {
        alias /home/laike9m/$1;
    }
    

    Solved it.