Link Search Menu Expand Document
Table of contents

Scenario 1 - simple try

server {
    listen 80;
    server_name 198.255.25.1;
    root /sites/demo; 

    try_files /apple.png /hello; 
    # if apple.png doesn't exist, nginx to return path /hello.
}

Scenario 2 - parse try request logic

server {
    listen 80;
    server_name 198.255.25.1;
    root /sites/demo; 

    try_files $uri /apple.png /hello /friendly_404;
    #trying path in it's order, remove below /hello location to get 404. 

    location /hello {
        return 200 "hello apple";
    }

    location /friendly_404 {
        return 404 "sorry, the file is not found";
    }      
}

Scenario 3 - nested parse try request logic

server {
    try_files path1 path2 final;
    location / {
        try_files path1 path2 final;
    }
}