Report this

What is the reason for this report?

Nginx location block for wordpress and legacy files

Posted on July 23, 2021
mji

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/mysite.com/htdocs;
                try_files $uri /legacy/$uri $uri/ @fallback;
}

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

However the uri http://mysite.com/ 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.



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!

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.

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 {

server_name myserver.com www.myserver.com;
access_log /var/log/nginx/myserver.com.access.log rt_cache_redis;
error_log /var/log/nginx/myserver.com.error.log;

root /var/www/myserver.com/htdocs;
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;

}

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.