0

In my test scenario if a file is being created and someone requests the file 404 will be returned. i want to implement a retry once for that file. current configuration

location /file/ {
    root /var/www/html/;
    try_files $uri $uri/ @retry;
}
location @retry {
    proxy_pass http://127.0.0.1;
}

this works fine for real time file creation and access (if a file returns 404 it retries sort of). but if a file doesn't exists it creates a nested requests (i guess) which will eventually return 503 gateway timeout.
1) is there any better implementation for this ?
2) will nested request also dies when 1st request times out ?

1 Answer 1

1

Simply duplicate your location block instead of proxying to localhost.

location /file/ {
    root /var/www/html/;
    try_files $uri $uri/ @retry;
}

location @retry {
    root /var/www/html/;
    try_files $uri $uri/ =404;
}

But considering how fast nginx is to process a request, this retry thing for a static file seems a really weird idea. You should fix what you have in mind in your workflow instead.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .