How-to use Media Vault with Nginx

The Media Vault plugin for WordPress is the only WordPress plugin that I’m aware of that allows you to protect uploaded files from public access. Protecting your WordPress web site is relatively easy and there a bunch of great plugins that help make your site private for internal use.

But there is a bit of a catch, the Media Vault plugin only supports Apache web servers. So if you’re running your WordPress installation on Nginx, there’s a small hack you need in order to make it work.

Step 1 – Install and modify the plugin

First of all install the Media Vault plugin like you normally would, and it will give you a message that you need to activate the Apache rewrite rules. Of course it won’t work, so in order to activate the plugin we’ll do this.

From the “Select plugin to edit:” menu select “Media Vault” and click Select

On the right-hand side click on the media-vault/_mediavault.php plugin file.

Look for a line that reads: “function mgjp_mv_check_rewrite_rules( $deactivation = false ) {“

Modify the return statement in that function so it reads: return true;

That simply makes the activation successful even though we don’t actually have it working yet. The reason we have to do this is because the nginx rewrite rules that we’re going to add work, but don’t pass the test in this function because they don’t return the same http codes that apache does.

This configure takes care of WordPress pretty-urls, Media Vault rules, and also redirects any old upload URLs from your media library to the new media vault protected URL. This was helpful in our case were we already had a lot of existing media in use in the WordPress site and it would have taken a lot of effort to update all the URLs on the pages.