Multisite WordPress nginx uploaded files throw 404

I have a WordPress subdomain multisite install in the /blog subdirectory running on an nginx server. Everything works fine except files which do upload correctly but are not accessible via their url.

The part of the config concerning the files is:

Read More
location ~ ^/files/(.*)$ {
    try_files /blog/wp-content/blogs.dir/$blogid/$uri /blog/wp-includes/ms-files.php?file=$1 ;
    access_log off; log_not_found off; expires max;
}

#avoid php readfile()
location ^~ /blogs.dir {
    internal;
    alias /var/www/example/public_html/blog/wp-content/blogs.dir;
    access_log off; log_not_found off;      expires max;
}

and

map $http_host $blogid {
    default       -999;

    #blog
    example.com             1;
    a.example.com           2;
    b.example.com           3;
    c.example.com           4;
}

The WordPress sites have the following settings:

Upload Path: wp-content/blogs.dir/1/files/

Upload Url Path: http://example.com/blog/files

Fileupload Url: http://example.com/blog/files

The number in the Upload Path is of course different for each site.

When I try to upload a file to any blogpost of any of the sites it does appear in the /blog/wp-content/blogs.dir/#/files/ folder but if I try to access /blog/wp-content/files/test.png it throws 404

Any ideas? Thanks!

Related posts

1 comment

  1. I solved the problem by upgrading the way files are uploaded and displayed to the new WordPress 3.5 method.

    A more detailed tutorial can be found at http://halfelf.org/2012/dumping-ms-files/ but the basic steps are as follows:

    • Move images from blogs.dir/#/files/ to /uploads/sites/#/
    • Change WordPress settings so it doesn’t look in /files/ but in /uploads/sites/#/
    • In .htaccess or your nginx config file remove ms-files.php line/section
    • Search/replace the posts table for each site, changing /files/ to /uploads/sites/#/

Comments are closed.