Access to production files without local storage on dev


If you are developing on a website already in production, you generally need to get all the /files/ repository to have access to all your "user uploaded" content.

Methods below allow you to have access to both the files from production and locally files without the need of download all distant resources.

You need to add the following instructions into your Vhost.

Get raw version
  1. /* For Nginx server */
  3. // Testing all files on /files/ repository
  4. // but exclude css and js to prevent errors.
  5. location ~ /sites/.*/files/.*(?!css|!js)$ {
  6. error_page 404 = @fetch;
  7. }
  9. // Redirect to prod URL.
  10. location @fetch {
  11. proxy_pass;
  12. }

Same for Apache

Get raw version
  1. /* For Apache server
  2. * In that example, we are not dealing with css and js risks as previous one.
  3. */
  5. RewriteCond %{REQUEST_URI} ^/sites/default/files/
  7. RewriteRule ^/(sites/default/files/.*)$1 [L]

Drupal's module alternative

Get raw version


misterjoonas's picture

Do you have any experience using this with varnish? I got the stage_file_proxy working on my local, which is not running varnish usually, but on the development server we have varnish and all the pictures generate a server 500. Both with stage_file_proxy and nginx conf trick.

Christine's picture

Hi! Thanks it works really well, only thing is now I can't login because of files persmissions. Any suggestions?

Stijn Huyberechts's picture

You should can use the Apache proxy module (mod_proxy and mod_proxy_http) to proxy pass the request instead of redirecting. That way it acts similar to the nginx solution. So enable mod_proxy_http (it also enables mod_proxy) if not already and change the rewrite rule flags:

RewriteRule ^/(sites/default/files/.*)$1 [P,QSA]

Note the QSA flag to append the request query string to the proxy request uri as well. The P (proxy) flag implies the L flag, so you can leave it out.