Nginx Multisite configuration subdirectories static content


#1

Hello, I have an issue with properly serving static content in Wordpress multisite network.

But when I try file like http://test.com/subsite3/wp-content/uploads/sites/3/2018/05/test.jpg it serves through php. This is old configuration and not working anymore as on wordpress 4.9.6 you don’t have folder blogs.dir, files, etc.

I have the following config in nginx. Please help me, because site have a lot of static content, and server goes down from time to time.

map $uri $blogname{
    ~^(?<blogpath>/[^/]+/)wp-content/(.*)   $blogpath ;

}

map $blogname $blogid{
    default -999;
    include /var/www/webroot/ROOT/wp-content/uploads/nginx-helper/map.conf ;

}

server {
listen       80 default_server;

    server_name  localhost;

    server_name_in_redirect off;

    root   /var/www/webroot/ROOT;

    index index.php;

if ($http_x_remote_port = '' ) {
        set $http_x_remote_port $remote_port;
    }

if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}

    location / {
            # This is cool because no php is touched for static content.
            # include the "?$args" part so non-default permalinks doesn't b$
            try_files $uri $uri/ /index.php?$args;
            auth_basic "Restricted content";
            auth_basic_user_file /var/www/webroot/.htpasswd;
    }

location ~ ^(/[^/]+/)?wp-content/(?<rt_file>.+) {
            try_files /wp-content/uploads/sites/$blogid/$rt_file /wp-includes/ms-files.php?file=$rt_file ;
            access_log off; log_not_found off; expires max;

    }
location ~ \.php$ {
            try_files $uri =404;
     #	location ~ /\. { deny all; access_log off; log_not_found off; }
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT $realpath_root;
            fastcgi_param PATH_INFO $fastcgi_script_name;

       }

}