Nginx location block for wordpress and legacy files

  • Posted on July 23, 2021
  • Nginx
  • mjiAsked by mji

Hi . I am trying to serve legacy html website documents from the new site which is a wordpress site.

The new site is using nginx and I want to be able to serve files which are structured with a permalink like /articles/file-uri and the 10 years of legacy html static files from a directory in the root called legacy.

I have had some success with these blocks :

index index.php;
location ^~ / {
root /var/www/;
                try_files $uri /legacy/$uri $uri/ @fallback;

location @fallback {
root /var/www/;
try_files $uri $uri/ /index.php$args; 

However the uri results in the index.php being forced as a download of text.

I do not see why the index.php file is being sent as application/octet-stream.

thank you for any help that you might provide.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi and thank you –

I changed the code again … to this below … it will partially work … but will not provide the images and secondary server hits from the static html files stored in /legacy

So, again, I want to try incoming request files against wordpress root and if the requested file is not found, search the legacy files for a static html article… This works but it will not go back to legacy for the image files, javascript, etc …

server {

access_log /var/log/nginx/ rt_cache_redis;
error_log /var/log/nginx/;

root /var/www/;
index index.php;

location ^~ .php$ { try_files $uri =404; include fastcgi_params; fastcgi_pass php74; }

location / { try_files $uri $uri/ /legacy$uri /index.php$args; }

include common/redis-php74.conf;
include common/wpcommon-php74.conf;
include common/locations-wo.conf;


Hi @mji,

That’s odd.

Anyway, can you post your full Nginx configuration file so that we can see if there was anything else that could be the problem?

Additionally, do you see any errors in your Nginx Error logs?

At the top of my mind I can’t see any obvious errors or reasons as to why this is happening.