Nginx location block for wordpress and legacy files

Posted July 23, 2021 142 views

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.

edited by KFSys

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.

Submit an Answer
2 answers

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.

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$ {
tryfiles $uri =404;
include fastcgi
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;