nginx rewrite virtual directory to file

Michael Gorham picture Michael Gorham · Sep 9, 2012 · Viewed 23.5k times · Source

This should be really easy to do but I'm hitting my head on the wall. If I get a request for www.mysite.com/mypath I want to serve the content of www.mysite.com/myotherpath/thisfile.html. How can I do this with an nginx config.

Answer

VBart picture VBart · Sep 10, 2012
location = /mypath {
    try_files /myotherpath/thisfile.html =404;
}