Nginx 404 when uri request is a file

Hello everyone.
I’m trying to manage a list of redirect from an old website to the new one.
All the redirect that I’m trying to dealing with are 404 link to a no more existing files (they are all pdf).
I tried first with the wp plugin redirection without success.

An example of link is which leads to an nginx 404 page.

My goal is to redirects alla my dead links to a specific page.
I thought that Nginx would have handled the problem by default according to this rule

  location / {
    try_files $uri $uri/ /index.php?$args;

calling the index.php as fallback and consequently allowing me to manage everything from the plugin.
Am I missing something?

Thank you in advance,

That nginx config should work. However, other config may also interfere.
I notice that when is requested, the 404 is not passed to WordPress. However, when the file extension is omitted (, the 404 is handled by WordPress.
Also unknown file extensions ( of non-existing files are handled by WordPress.

So there is probably some nginx configuration for common file extensions (pdf; jpeg; jpg; …) that apply before the config to pass the 404 to WordPress.

From the trellis tag of your post I assume that this server is a Trellis server.
Are you using a recent Trellis? What is the last line in the of your Trellis?

Thank you for your answer.
Yes, correct. I’m using trellis, and yes, it’s an old versione 1.0.3 if I remember well.
Any advice on how to fix my trellis config?

Thank you,

@strarsis sorry for bothering you again.
I’ve tried to go through the commits, but I did’t find anything for the scope.
Any hint on that?
Thanks so much

How do the nginx configuration files contain, especially for that site?
Was nginx restarted for eventual non-applied nginx configuration?

Ideally you would spin up a staging server or VM (that is as closely to your current production server as possible, in terms of OS/LTS/CPU/memory) and apply your current, older Trellis on it, also deploy the sites onto it.
Then you would update your current, older Trellis with latest upstream Trellis (requires some merging and scrutinizing of changed stuff, but usually this is quite easy).
Then apply your updated Trellis on the staging server/VM and check whether the re-provision worked and also deploy each site and also check if deployments worked.
Afterwards validate whether that 404 bug is gone now and all the sites are still running fine.
Then finally you can re-provision your production system and re-deploy your sites.