nginx – Hello :) https://blog.samyapp.com Wed, 20 Apr 2016 09:04:51 +0000 en-US hourly 1 https://wordpress.org/?v=4.8.7 102402223 Redirect requests for missing wordpress uploads to another server using NGINX https://blog.samyapp.com/redirect-requests-for-missing-wordpress-uploads-to-another-server-using-nginx/ https://blog.samyapp.com/redirect-requests-for-missing-wordpress-uploads-to-another-server-using-nginx/#respond Wed, 20 Apr 2016 08:58:48 +0000 https://blog.samyapp.com/?p=453 When working on a copy of a live WordPress website it can be handy not to have to duplicate the uploaded files in wp-content/uploads, whilst still allowing the creation of new uploads during testing and development without affecting the production website. The configuration below can be added inside a server{} block inside an NGINX configuration […]

The post Redirect requests for missing wordpress uploads to another server using NGINX appeared first on Hello :).

]]>
When working on a copy of a live WordPress website it can be handy not to have to duplicate the uploaded files in wp-content/uploads, whilst still allowing the creation of new uploads during testing and development without affecting the production website.

The configuration below can be added inside a server{} block inside an NGINX configuration file to redirect any requests for files in wp-content/uploads that don’t exist back to the live server, www.example.com.

server {

# ... other server configuration... 

    # Match anything in wp-content/uploads and if it doesn't exist, use the rule for @prod_serv
    location ~ "^(.*)/wp-content/uploads/(.*)$" {
        try_files $uri @prod_server;
    }

    # Send a temporary http redirect to the browser, redirecting the request to 
    # For a permanent redirect change the status code below from 302 to 301
    location @prod_serv {
        return 302 $scheme://www.example.com$request_uri;
    }

# ... rest of the server config below ...
}

This solution was based on the information at http://wordpress.stackexchange.com/a/215189 and https://www.nginx.com/blog/creating-nginx-rewrite-rules/ .

The post Redirect requests for missing wordpress uploads to another server using NGINX appeared first on Hello :).

]]>
https://blog.samyapp.com/redirect-requests-for-missing-wordpress-uploads-to-another-server-using-nginx/feed/ 0 453