0

'm trying to find way how to serve cached files with nginx.

I have stored search results to json file in shared memory. Next time when user tries to look up the same search, it supposed to be served by nginx by try_files directive.

Here is the request string:

/api/ajax-ticker-search?search=SBER 

Here is what I have in nginx:

location /api/ajax-ticker-search/ { try_files /dev/shm/searchResults/$arg_search.json @apisearch; } 

I do have file named SBER.json in /dev/shm/searchResults but nginx is not serving it, always falling back to @apisarch location.

What's wrong with try_files and how can make it work and serve stored json file?

1 Answer 1

0

OK, I've managed this to work, but still don't understand how.

Here is working config:

location /api/ajax-ticker-search { root /dev/shm/search; try_files /$arg_search @apisearch; } 

What I did:

  • moved files from searchResults folder to search folder (no camel case folders?);

    • put root directive before try_files so filename in try_files directive is now just /$arg_search instead of /dev/shm/search/$arg_search. (Have to set root?)

    • removed .json extension (Just in case)

I have no idea which of theses actually helped, but now it works and I can cache search results from PHP directly to file that then is being read by nginx.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.