As a follow up on this topic, I’m trying to use production (or external) media uploads in my development environment.
A symlink uploads folder is not working and a synced uploads folder to an external wouldn’t work either in a shared code base.
So I’m back at making it work with a nginx child template.
I found this snippet that uses the production media url if the local media url is not found:
{% extends 'roles/wordpress-setup/templates/wordpress-site.conf.j2' %}
{% block location_primary -%}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ "^(.*)/app/uploads/(.*)$" {
try_files $uri @production;
}
location @production {
rewrite "^(.*)/app/uploads/(.*)$" "https://example.com/app/uploads/$2" redirect;
}
{% endblock %}
I used it in other projects that had a flat uploads folder (not monthly & yearly organized) and that worked perfectly!
So I’m trying to make this work with a monthly & yearly organized folder structure:
{% extends 'roles/wordpress-setup/templates/wordpress-site.conf.j2' %}
{% block location_primary -%}
location ~ "^(.*)/app/uploads/(.*)$" {
try_files $uri $uri/ @production;
}
location @production {
rewrite "^(.*)/app/uploads/([0-9]+/[0-9]+/)?(.*)$" "https://example.com/app/uploads/$2$3" redirect;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
{% endblock %}
But this is not working yet unfortunately…
I keep getting 404 Not Found for every upload, it’s not redirecting to the production url.
Any ideas?